HemanM commited on
Commit
2fec12b
Β·
verified Β·
1 Parent(s): 7a7ebad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -40
app.py CHANGED
@@ -1,58 +1,66 @@
 
 
1
  import gradio as gr
2
  from inference import get_evo_response, get_gpt_response
3
- from logger import log_feedback
4
- import retrain
5
  import pandas as pd
6
  import os
7
 
8
- def advisor_interface(question, context, options_text, feedback_choice):
9
- options = [opt.strip() for opt in options_text.split("\n") if opt.strip()]
10
- evo_output, evo_reasoning = get_evo_response(question, context, options)
11
- gpt_output = get_gpt_response(question, context, options)
 
 
 
 
 
12
 
13
- if feedback_choice != "No feedback":
14
- label = 1 if feedback_choice == "πŸ‘ Helpful" else 0
15
- log_feedback(question, context, evo_output, label)
16
 
17
- return evo_reasoning, gpt_output, load_history()
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- def retrain_evo():
20
- retrain.fine_tune_on_feedback()
21
- return "βœ… Evo retrained on feedback.", load_history()
22
 
23
  def load_history():
24
- if os.path.exists("feedback_log.csv"):
25
- df = pd.read_csv("feedback_log.csv")
26
- try:
27
- return df.tail(10).to_markdown(index=False)
28
- except ImportError:
29
- return "πŸ“œ History available, but markdown rendering failed. Install `tabulate` for full view."
30
- return "No history available yet."
31
 
32
  with gr.Blocks() as demo:
33
- gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with RAG + Web Search")
34
 
35
  with gr.Row():
36
- question = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. Who is the current president of the US?")
37
- with gr.Row():
38
- options_text = gr.Textbox(label="πŸ”’ Options (one per line)", placeholder="Option 1\nOption 2\nOption 3", lines=4)
39
- with gr.Row():
40
- context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", placeholder="Paste memo, article, or info here...", lines=4)
41
 
42
- feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful", "No feedback"], label="Was Evo’s answer useful?", value="No feedback")
 
 
 
43
 
44
- with gr.Row():
45
- evo_out = gr.Textbox(label="πŸ”¬ EvoRAG Suggestion (with reasoning)")
46
- gpt_out = gr.Textbox(label="πŸ€– GPT-3.5 Suggestion")
47
-
48
- run_button = gr.Button("Run Advisors")
49
- run_button.click(fn=advisor_interface, inputs=[question, context, options_text, feedback], outputs=[evo_out, gpt_out, gr.Textbox(label="πŸ“œ Recent History")])
50
-
51
- gr.Markdown("---")
52
- gr.Markdown("### πŸ” Retrain Evo from Feedback")
53
- retrain_button = gr.Button("πŸ“š Retrain Evo")
54
- retrain_output = gr.Textbox(label="πŸ› οΈ Retrain Status")
55
- history_output = gr.Textbox(label="πŸ“œ Recent History")
56
- retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_output, history_output])
57
 
58
  demo.launch()
 
1
+ # app.py
2
+
3
  import gradio as gr
4
  from inference import get_evo_response, get_gpt_response
 
 
5
  import pandas as pd
6
  import os
7
 
8
+ LOG_PATH = "feedback_log.csv"
9
+ os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
10
+ if not os.path.exists(LOG_PATH):
11
+ pd.DataFrame(columns=["question", "context", "option1", "option2", "evo_answer", "feedback"]).to_csv(LOG_PATH, index=False)
12
+
13
+ def advisor_interface(question, context, options_text, feedback=None):
14
+ options = [o.strip() for o in options_text.split("\n") if o.strip()]
15
+ if len(options) != 2:
16
+ return "Please enter exactly two options (one per line).", "", ""
17
 
18
+ option1, option2 = options
19
+ evo_answer, confidence, s1, s2 = get_evo_response(question, option1, option2)
20
+ gpt_output = get_gpt_response(question, option1, option2)
21
 
22
+ # Log feedback if given
23
+ if feedback:
24
+ df = pd.read_csv(LOG_PATH)
25
+ df = df.append({
26
+ "question": question,
27
+ "context": context,
28
+ "option1": option1,
29
+ "option2": option2,
30
+ "evo_answer": evo_answer,
31
+ "feedback": feedback
32
+ }, ignore_index=True)
33
+ df.to_csv(LOG_PATH, index=False)
34
 
35
+ evo_msg = f"Evo suggests: **{evo_answer}** (Confidence: {confidence:.2f})"
36
+ context_used = f"Option 1 Score: {s1:.2f}\nOption 2 Score: {s2:.2f}"
37
+ return evo_msg + "\n\n" + context_used, gpt_output, load_history()
38
 
39
  def load_history():
40
+ df = pd.read_csv(LOG_PATH)
41
+ if df.empty:
42
+ return "No feedback yet."
43
+ return df.tail(10).to_markdown(index=False)
 
 
 
44
 
45
  with gr.Blocks() as demo:
46
+ gr.Markdown("🧠 **EvoRAG – General-Purpose Adaptive AI with Web Reasoning**")
47
 
48
  with gr.Row():
49
+ with gr.Column():
50
+ question = gr.Textbox(label="πŸ“ Ask anything")
51
+ context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", lines=2)
52
+ options = gr.Textbox(label="🧠 Options (Enter two options, one per line)", placeholder="Option 1\nOption 2")
53
+ run_btn = gr.Button("πŸ” Run Advisors")
54
 
55
+ feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful", "No feedback"], label="Was Evo’s answer useful?")
56
+ evo_out = gr.Markdown()
57
+ gpt_out = gr.Markdown()
58
+ history = gr.Markdown()
59
 
60
+ run_btn.click(
61
+ advisor_interface,
62
+ inputs=[question, context, options, feedback],
63
+ outputs=[evo_out, gpt_out, history]
64
+ )
 
 
 
 
 
 
 
 
65
 
66
  demo.launch()