ajaynagotha commited on
Commit
fdd82d8
·
verified ·
1 Parent(s): 631f030

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ model_name = "google/flan-t5-xl"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
+
8
+ gita_context = """
9
+ The Bhagavad Gita is a 700-verse Hindu scripture that is part of the Indian epic Mahabharata. It is a dialogue between Prince Arjuna and Lord Krishna, who serves as his charioteer. The Gita's core message includes:
10
+ 1. The immortality of the soul (Atman)
11
+ 2. The nature of action (Karma) and duty (Dharma)
12
+ 3. The importance of devotion (Bhakti)
13
+ 4. The pursuit of knowledge (Jnana) and wisdom
14
+ 5. Different types of Yoga: Karma Yoga, Bhakti Yoga, Jnana Yoga, and Raja Yoga
15
+ 6. The concept of detachment from the fruits of one's actions
16
+ 7. The divine nature of Krishna as an avatar of Vishnu
17
+ Key teachings include performing one's duty without attachment to results, the importance of self-realization, and the path to liberation (Moksha).
18
+ """
19
+
20
+ def generate_response(question):
21
+ prompt = f"Based on the following context about the Bhagavad Gita, answer the question.\n\nContext: {gita_context}\n\nQuestion: {question}\n\nAnswer:"
22
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
23
+ outputs = model.generate(input_ids, max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.95)
24
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
25
+ return response
26
+
27
+ iface = gr.Interface(
28
+ fn=generate_response,
29
+ inputs=gr.Textbox(lines=2, placeholder="Enter your question about the Bhagavad Gita here..."),
30
+ outputs="text"
31
+ )
32
+
33
+ iface.launch()