HemanM commited on
Commit
3363688
Β·
verified Β·
1 Parent(s): 93127e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -5,13 +5,14 @@ import retrain
5
  import pandas as pd
6
  import os
7
 
8
- def advisor_interface(query, context, feedback_choice):
9
- evo_output, evo_reasoning = get_evo_response(query, context)
10
- gpt_output = get_gpt_response(query, context)
 
11
 
12
  if feedback_choice != "No feedback":
13
  label = 1 if feedback_choice == "πŸ‘ Helpful" else 0
14
- log_feedback(query, context, evo_output, label)
15
 
16
  return evo_reasoning, gpt_output, load_history()
17
 
@@ -22,32 +23,36 @@ def retrain_evo():
22
  def load_history():
23
  if os.path.exists("feedback_log.csv"):
24
  df = pd.read_csv("feedback_log.csv")
25
- return df.tail(10).to_markdown(index=False)
 
 
 
26
  return "No history available yet."
27
 
28
  with gr.Blocks() as demo:
29
  gr.Markdown("## 🧠 EvoRAG – General-Purpose Adaptive AI with RAG + Web Search")
30
 
31
  with gr.Row():
32
- query = gr.Textbox(label="πŸ“ Ask anything", placeholder="e.g. What are the latest trends in AI regulation?")
33
- context = gr.Textbox(label="πŸ“‚ Optional Context or Notes", placeholder="Paste any relevant information or leave blank.")
34
-
35
  with gr.Row():
36
- feedback = gr.Radio(["πŸ‘ Helpful", "πŸ‘Ž Not Helpful", "No feedback"], label="Was Evo’s answer useful?", value="No feedback")
 
 
37
 
38
  with gr.Row():
39
  evo_out = gr.Textbox(label="πŸ”¬ EvoRAG Suggestion (with reasoning)")
40
  gpt_out = gr.Textbox(label="πŸ€– GPT-3.5 Suggestion")
41
 
42
  run_button = gr.Button("Run Advisors")
43
- run_button.click(fn=advisor_interface, inputs=[query, context, feedback], outputs=[evo_out, gpt_out, gr.Textbox(label="πŸ“œ Recent History")])
44
 
45
  gr.Markdown("---")
46
  gr.Markdown("### πŸ” Retrain Evo from Feedback")
47
  retrain_button = gr.Button("πŸ“š Retrain Evo")
48
  retrain_output = gr.Textbox(label="πŸ› οΈ Retrain Status")
49
  history_output = gr.Textbox(label="πŸ“œ Recent History")
50
-
51
  retrain_button.click(fn=retrain_evo, inputs=[], outputs=[retrain_output, history_output])
52
 
53
  demo.launch()
 
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
 
 
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()