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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -75
app.py CHANGED
@@ -1,98 +1,62 @@
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()
 
1
  import gradio as gr
2
  from inference import get_evo_response, get_gpt_response
 
3
  import os
4
+ from logger import log_feedback
5
 
6
  LOG_PATH = "feedback_log.csv"
7
+ os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True) if os.path.dirname(LOG_PATH) else None
 
 
 
 
 
8
 
9
+ def process_inputs(query, option_1, option_2, user_context):
10
+ options = [option_1, option_2]
11
+ evo_answer, reasoning, confidence, evo_context = get_evo_response(query, options, user_context)
12
+ gpt_answer = get_gpt_response(query, user_context)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  return (
14
+ evo_answer,
15
  reasoning,
16
+ f"Context used by Evo:\n{evo_context}",
17
+ gpt_answer
 
 
18
  )
19
 
20
+ def feedback_submit(question, context, evo_answer, feedback):
21
+ log_feedback(question, context, evo_answer, feedback)
22
+ return "βœ… Feedback submitted. Thank you!"
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  with gr.Blocks(title="🧠 EvoRAG – General-Purpose Adaptive AI with Web Reasoning") as demo:
25
  gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with Web Reasoning")
 
26
 
27
  with gr.Row():
28
+ with gr.Column():
29
+ query = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. Who is the current president of the US?")
30
+ user_context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", placeholder="Paste extra info or leave blank")
31
+ option_1 = gr.Textbox(label="πŸ”Ή Option 1", placeholder="e.g. Donald Trump")
32
+ option_2 = gr.Textbox(label="πŸ”Έ Option 2", placeholder="e.g. Joe Biden")
33
+ run_btn = gr.Button("πŸ” Get Answers")
34
+
35
+ with gr.Column():
36
+ gr.Markdown("### 🧠 EvoRAG Suggestion")
37
+ evo_out = gr.Textbox(label="Answer (Evo)", interactive=False)
38
+ evo_reason = gr.Textbox(label="Reasoning", interactive=False)
39
+ evo_context_used = gr.Textbox(label="Context Used", lines=4, interactive=False)
40
+
41
+ gr.Markdown("### πŸ€– GPT-3.5 Suggestion")
42
+ gpt_out = gr.Textbox(label="Answer (GPT-3.5)", interactive=False)
 
 
 
43
 
44
  run_btn.click(
45
+ fn=process_inputs,
46
+ inputs=[query, option_1, option_2, user_context],
47
+ outputs=[evo_out, evo_reason, evo_context_used, gpt_out]
48
  )
49
 
50
+ gr.Markdown("### πŸ—³οΈ Feedback")
51
+ with gr.Row():
52
+ feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful"], label="Was Evo’s answer useful?")
53
+ submit_btn = gr.Button("πŸ“¬ Submit Feedback")
54
+ feedback_result = gr.Textbox(visible=False)
55
+
56
  submit_btn.click(
57
+ fn=feedback_submit,
58
+ inputs=[query, user_context, evo_out, feedback],
59
+ outputs=[feedback_result]
60
  )
61
 
62
  demo.launch()