HemanM commited on
Commit
9a14224
Β·
verified Β·
1 Parent(s): e87c15e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -43
app.py CHANGED
@@ -1,67 +1,98 @@
1
- import os
2
  import gradio as gr
3
- import pandas as pd
4
  from inference import get_evo_response, get_gpt_response
 
 
5
 
6
  LOG_PATH = "feedback_log.csv"
7
- if os.path.dirname(LOG_PATH):
8
- os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
9
-
10
- def log_feedback(question, context, evo_answer, feedback):
11
- df = pd.DataFrame([[question, context, evo_answer, feedback]],
12
- columns=["question", "context", "evo_answer", "feedback"])
13
- if os.path.exists(LOG_PATH):
14
- df.to_csv(LOG_PATH, mode="a", header=False, index=False)
15
- else:
16
- df.to_csv(LOG_PATH, index=False)
17
-
18
- def load_history():
19
  if not os.path.exists(LOG_PATH):
20
- return "No feedback yet."
21
- df = pd.read_csv(LOG_PATH)
22
- return df.tail(10).to_markdown(index=False)
 
 
23
 
24
- def advisor_interface(query, context, options_input):
25
  options = [opt.strip() for opt in options_input.strip().split("\n") if opt.strip()]
26
  if len(options) != 2:
27
- return "Please enter exactly two options (one per line).", "", ""
28
 
29
- evo_answer, evo_reasoning, evo_conf, evo_context = get_evo_response(query, options, context)
30
- gpt_answer = get_gpt_response(query, context)
31
- history = load_history()
 
 
 
 
 
 
 
 
 
 
 
 
32
  return (
33
- f"### Evo Suggestion\n**Answer**: {evo_answer} (Confidence: {evo_conf:.2f})\n\n**Reasoning**: {evo_reasoning}\n\n_Context used:_\n{evo_context}",
34
- f"### GPT-3.5 Suggestion\n{gpt_answer}",
 
 
 
35
  history
36
  )
37
 
38
- def feedback_interface(question, context, evo_answer, feedback):
39
- log_feedback(question, context, evo_answer, feedback)
40
- return "βœ… Feedback logged."
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- with gr.Blocks(title="EvoRAG – General-Purpose Adaptive AI with Web Reasoning") as demo:
43
  gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with Web Reasoning")
 
44
 
45
  with gr.Row():
46
- with gr.Column():
47
- query = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. Who is the president of the US?")
48
- context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", lines=3, placeholder="Paste extra info or leave blank")
49
- options = gr.Textbox(label="🧠 Options (2 lines)", lines=2, placeholder="Option 1\nOption 2")
50
- submit = gr.Button("πŸ” Run Advisors")
51
 
52
- with gr.Column():
53
- evo_output = gr.Markdown()
54
- gpt_output = gr.Markdown()
 
 
 
 
55
 
56
  with gr.Row():
57
- feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful"], label="Was Evo’s answer useful?")
58
- submit_feedback = gr.Button("πŸ“¬ Submit Feedback")
59
- feedback_status = gr.Textbox(interactive=False)
60
 
61
- with gr.Accordion("πŸ“œ Recent History", open=False):
62
- history_display = gr.Markdown()
63
 
64
- submit.click(fn=advisor_interface, inputs=[query, context, options], outputs=[evo_output, gpt_output, history_display])
65
- submit_feedback.click(fn=feedback_interface, inputs=[query, context, evo_output, feedback], outputs=[feedback_status])
 
 
 
 
 
 
 
 
 
66
 
67
  demo.launch()
 
 
1
  import gradio as gr
 
2
  from inference import get_evo_response, get_gpt_response
3
+ import csv
4
+ import os
5
 
6
  LOG_PATH = "feedback_log.csv"
7
+ if LOG_PATH:
8
+ os.makedirs(os.path.dirname(LOG_PATH) or ".", exist_ok=True)
 
 
 
 
 
 
 
 
 
 
9
  if not os.path.exists(LOG_PATH):
10
+ with open(LOG_PATH, "w", newline="") as f:
11
+ writer = csv.writer(f)
12
+ writer.writerow(["question", "context", "evo_answer", "gpt_answer", "feedback"])
13
+
14
+ history = []
15
 
16
+ def run_advisors(query, options_input, context_input):
17
  options = [opt.strip() for opt in options_input.strip().split("\n") if opt.strip()]
18
  if len(options) != 2:
19
+ return "Please enter exactly two options (one per line).", "", "", "", "", history
20
 
21
+ evo_ans, reasoning, confidence, evo_context = get_evo_response(query, options, context_input)
22
+ gpt_ans = get_gpt_response(query, context_input)
23
+
24
+ entry = {
25
+ "Question": query,
26
+ "Context": context_input,
27
+ "Options": options,
28
+ "Evo Answer": evo_ans,
29
+ "Evo Score": reasoning,
30
+ "Confidence": f"{confidence:.2f}",
31
+ "Context Used": evo_context,
32
+ "GPT Answer": gpt_ans
33
+ }
34
+
35
+ history.insert(0, entry)
36
  return (
37
+ f"βœ… Answer: **{evo_ans}** (Confidence: {confidence:.2f})",
38
+ reasoning,
39
+ evo_context,
40
+ gpt_ans,
41
+ "", # feedback placeholder
42
  history
43
  )
44
 
45
+ def log_feedback(feedback, question, context, evo_answer, gpt_answer):
46
+ with open(LOG_PATH, "a", newline="") as f:
47
+ writer = csv.writer(f)
48
+ writer.writerow([question, context, evo_answer, gpt_answer, feedback])
49
+ return "βœ… Feedback submitted."
50
+
51
+ def render_history(history):
52
+ if not history:
53
+ return "No previous questions."
54
+ html = ""
55
+ for h in history[:5]:
56
+ html += f"<b>Q:</b> {h['Question']}<br>"
57
+ html += f"<b>Options:</b> {', '.join(h['Options'])}<br>"
58
+ html += f"<b>Evo:</b> {h['Evo Answer']} ({h['Evo Score']})<br>"
59
+ html += f"<b>GPT:</b> {h['GPT Answer']}<br><hr>"
60
+ return html
61
 
62
+ with gr.Blocks(title="🧠 EvoRAG – General-Purpose Adaptive AI with Web Reasoning") as demo:
63
  gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with Web Reasoning")
64
+ gr.Markdown("Ask any question and compare Evo’s evolved reasoning with GPT-3.5. Evo uses online context + live evolution.")
65
 
66
  with gr.Row():
67
+ query = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. Who is the president of France?")
68
+ options_input = gr.Textbox(lines=2, label="🧠 Options (2 lines)", placeholder="Option 1\nOption 2")
69
+ context_input = gr.Textbox(lines=2, label="πŸ“‚ Optional Context or Notes", placeholder="Paste extra info or leave blank")
 
 
70
 
71
+ run_btn = gr.Button("πŸ” Run Advisors")
72
+
73
+ evo_output = gr.Markdown()
74
+ reasoning_output = gr.Textbox(label="πŸ“Š Evo Reasoning")
75
+ evo_context = gr.Textbox(label="🌐 Web Context Used", lines=4)
76
+
77
+ gpt_output = gr.Textbox(label="πŸ€– GPT-3.5 Suggestion")
78
 
79
  with gr.Row():
80
+ feedback_radio = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful"], label="Was Evo’s answer useful?")
81
+ submit_btn = gr.Button("πŸ“¬ Submit Feedback")
 
82
 
83
+ feedback_status = gr.Markdown()
84
+ history_display = gr.HTML(label="πŸ“œ Recent History")
85
 
86
+ run_btn.click(
87
+ run_advisors,
88
+ inputs=[query, options_input, context_input],
89
+ outputs=[evo_output, reasoning_output, evo_context, gpt_output, feedback_radio, history_display]
90
+ )
91
+
92
+ submit_btn.click(
93
+ log_feedback,
94
+ inputs=[feedback_radio, query, context_input, evo_output, gpt_output],
95
+ outputs=feedback_status
96
+ )
97
 
98
  demo.launch()