HemanM commited on
Commit
b256639
·
verified ·
1 Parent(s): f718bd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -23
app.py CHANGED
@@ -1,28 +1,41 @@
1
  import gradio as gr
2
  from generate import generate_response
3
 
4
- def chat_interface(question, context, use_rag, temperature):
5
- try:
6
- answer = generate_response(question, context, use_rag=use_rag, temperature=temperature)
7
- return answer if answer else "(No meaningful response generated.)"
8
- except Exception as e:
9
- return f"(Error: {str(e)})"
 
 
 
 
 
10
 
11
  title = "🧠 EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval"
12
- description = "Ask a question with optional context. Evo was fine-tuned on SQuAD v2.\nToggle RAG for live web search if no context is available."
13
-
14
- iface = gr.Interface(
15
- fn=chat_interface,
16
- inputs=[
17
- gr.Textbox(label="❓ Question"),
18
- gr.Textbox(label="📄 Context (Optional)", lines=5, placeholder="Paste context or leave blank to use RAG"),
19
- gr.Checkbox(label="🔍 Use RAG (Live Web Search)"),
20
- gr.Slider(0.1, 1.5, value=1.0, label="🔥 Temperature")
21
- ],
22
- outputs=gr.Textbox(label="🤖 Evo's Answer"),
23
- title=title,
24
- description=description,
25
- )
26
-
27
- if __name__ == "__main__":
28
- iface.launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from generate import generate_response
3
 
4
+ def answer_question(question, context, use_rag, temperature):
5
+ if not question.strip():
6
+ return "❌ Please enter a question."
7
+
8
+ answer = generate_response(
9
+ question=question,
10
+ context=context.strip(),
11
+ use_rag=use_rag,
12
+ temperature=temperature
13
+ )
14
+ return answer or "(No meaningful response generated.)"
15
 
16
  title = "🧠 EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval"
17
+ description = "Ask a question with optional context. Evo was fine-tuned on SQuAD v2. Toggle RAG for live web search if no context is available."
18
+
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown(f"# {title}")
21
+ gr.Markdown(description)
22
+
23
+ with gr.Row():
24
+ question = gr.Textbox(label=" Question", placeholder="e.g. What is the capital of Japan?")
25
+
26
+ context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG", lines=4)
27
+
28
+ with gr.Row():
29
+ use_rag = gr.Checkbox(label="🔍 Use RAG (Live Web Search)", value=False)
30
+ temperature = gr.Slider(0.1, 1.5, value=1.0, step=0.1, label="🔥 Temperature")
31
+
32
+ with gr.Row():
33
+ submit = gr.Button("Submit")
34
+ clear = gr.Button("Clear")
35
+
36
+ output = gr.Textbox(label="🤖 Evo's Answer", lines=4)
37
+
38
+ submit.click(fn=answer_question, inputs=[question, context, use_rag, temperature], outputs=output)
39
+ clear.click(fn=lambda: ("", "", False, 1.0, ""), inputs=[], outputs=[question, context, use_rag, temperature, output])
40
+
41
+ demo.launch()