HemanM commited on
Commit
95a6056
Β·
verified Β·
1 Parent(s): 76788c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -69
app.py CHANGED
@@ -63,83 +63,58 @@ demo.launch()'''
63
  import gradio as gr
64
  from inference import get_evo_response, get_gpt_response
65
  from logger import log_feedback
66
- import os
67
 
68
- LOG_PATH = "feedback_log.csv"
69
- if os.path.dirname(LOG_PATH):
70
- os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
71
-
72
- # πŸ” Core logic for response generation
73
- def run_comparison(question, option1, option2, notes):
74
- options = [option1, option2]
75
- evo_ans, reasoning, confidence, evo_context = get_evo_response(question, options, notes)
76
- gpt_ans = get_gpt_response(question, notes)
77
-
78
- evo_output = f"""
79
- ### βœ… Evo's Suggestion: **{evo_ans}**
80
- **🧠 Reasoning:**
81
- {reasoning}
82
-
83
- **πŸ“š Context Used:**
84
- {evo_context}
85
- """
86
-
87
- gpt_output = f"""
88
- ### πŸ€– GPT-3.5 Suggestion
89
- {gpt_ans}
90
- """
91
-
92
- return evo_output.strip(), gpt_output.strip()
93
-
94
- # 🧠 Feedback logic
95
- def save_feedback(question, notes, evo_output, feedback):
96
- log_feedback(question, notes, evo_output, feedback)
97
- if feedback == "πŸ‘ Evo was correct. Retrain from this.":
98
- return "βœ… Evo will be retrained with your feedback."
99
- return "πŸ“© Feedback recorded. Thanks!"
100
-
101
- with gr.Blocks(title="EvoRAG – General-Purpose AI with Web Reasoning") as demo:
102
- gr.Markdown("""
103
- <div style="text-align: center; font-size: 32px; font-weight: bold; color: #222">🧠 EvoRAG</div>
104
- <div style="text-align: center; font-size: 16px; margin-bottom: 20px; color: #444">
105
- General-Purpose Adaptive AI that Thinks, Reads, and Evolves – Powered by Real-Time Web Search
106
- </div>
107
- """)
108
 
109
  with gr.Row():
110
  with gr.Column():
111
- question = gr.Textbox(label="πŸ“ Your Question", placeholder="e.g. What should I do if my house is on fire?")
112
- option1 = gr.Textbox(label="πŸ”Ή Option 1", placeholder="e.g. I hide under the bed")
113
- option2 = gr.Textbox(label="πŸ”Έ Option 2", placeholder="e.g. I run for dear life")
114
- notes = gr.Textbox(label="πŸ“‚ Extra Notes or Context (Optional)", lines=4, placeholder="Paste news, user context, or background information")
115
- run_button = gr.Button("πŸš€ Run Comparison")
116
 
117
  with gr.Column():
118
- gr.Markdown("### 🧠 EvoRAG's Response")
119
- evo_output = gr.Markdown()
120
- gr.Markdown("### πŸ€– GPT-3.5's Suggestion")
121
- gpt_output = gr.Markdown()
122
-
123
- run_button.click(
124
- fn=run_comparison,
125
- inputs=[question, option1, option2, notes],
126
- outputs=[evo_output, gpt_output]
127
- )
128
 
129
- gr.Markdown("### πŸ” Help Evo Learn – Give Feedback")
130
- with gr.Row():
131
- feedback = gr.Radio(
132
- ["πŸ‘ Evo was correct. Retrain from this.", "πŸ‘Ž Evo was wrong."],
133
- label="What did you think of Evo's answer?"
134
- )
135
- submit_button = gr.Button("πŸ“¬ Submit Feedback / Retrain Evo")
136
- feedback_status = gr.Textbox(visible=False)
137
-
138
- submit_button.click(
139
- fn=save_feedback,
140
- inputs=[question, notes, evo_output, feedback],
141
  outputs=[feedback_status]
142
  )
143
 
144
  demo.launch()
145
-
 
63
  import gradio as gr
64
  from inference import get_evo_response, get_gpt_response
65
  from logger import log_feedback
 
66
 
67
+ # Default demo
68
+ default_question = "What should I do if my house is on fire?"
69
+ default_option1 = "I hide under the bed"
70
+ default_option2 = "I run for dear life"
71
+ default_context = ""
72
+
73
+ def run_comparison(question, option1, option2, context):
74
+ options = [option1.strip(), option2.strip()]
75
+ evo_answer, evo_reasoning, evo_conf, evo_context = get_evo_response(question, options, context)
76
+ gpt_answer = get_gpt_response(question, context)
77
+
78
+ evo_output = f"""**βœ… Evo's Suggestion:** {evo_answer}\n\n**Why?** {evo_reasoning}\n\n**Context Used:** {evo_context[:500]}..."""
79
+ gpt_output = f"""**πŸ€– GPT-3.5's Suggestion:**\n\n{gpt_answer}"""
80
+
81
+ return evo_output, gpt_output
82
+
83
+ def handle_feedback(evo_was_correct, question, option1, option2, context, evo_output):
84
+ if evo_was_correct is not None:
85
+ log_feedback(question, option1, option2, context, evo_output, evo_was_correct)
86
+ return "βœ… Feedback recorded. Evo will retrain based on this soon!"
87
+ return "⚠️ Please select feedback before submitting."
88
+
89
+ with gr.Blocks(theme=gr.themes.Base(), title="EvoRAG - Smarter Than GPT?") as demo:
90
+ gr.Markdown("## 🧠 EvoRAG")
91
+ gr.Markdown("**General-Purpose Adaptive AI that Thinks, Reads, and Evolves β€” Powered by Real-Time Web Search**")
92
+ gr.Markdown("> Compare reasoning between Evo (which learns) and GPT-3.5 (which doesn't). You decide who wins.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  with gr.Row():
95
  with gr.Column():
96
+ question = gr.Textbox(label="❓ Your Question", placeholder="e.g. What should I do if my house is on fire?", value=default_question)
97
+ option1 = gr.Textbox(label="πŸ”Ή Option 1", placeholder="e.g. I hide under the bed", value=default_option1)
98
+ option2 = gr.Textbox(label="πŸ”Έ Option 2", placeholder="e.g. I run for dear life", value=default_option2)
99
+ context = gr.Textbox(label="πŸ“‚ Extra Notes or Context (Optional)", placeholder="Paste news, user context, or background information", lines=4, value=default_context)
100
+ compare_btn = gr.Button("πŸš€ Think & Compare")
101
 
102
  with gr.Column():
103
+ evo_out = gr.Markdown(label="🧬 EvoRAG's Response")
104
+ gpt_out = gr.Markdown(label="πŸ€– GPT-3.5's Suggestion")
 
 
 
 
 
 
 
 
105
 
106
+ compare_btn.click(fn=run_comparison, inputs=[question, option1, option2, context], outputs=[evo_out, gpt_out])
107
+
108
+ gr.Markdown("---")
109
+ gr.Markdown("### 🧠 Help Evo Get Smarter – Give Feedback")
110
+ feedback = gr.Radio(["πŸ‘ Evo was correct. Retrain from this.", "πŸ‘Ž Evo was wrong."], label="What did you think of Evo's answer?")
111
+ submit_feedback = gr.Button("πŸ“¬ Submit Feedback / Retrain Evo")
112
+ feedback_status = gr.Textbox(label="", interactive=False)
113
+
114
+ submit_feedback.click(
115
+ fn=lambda fb, q, o1, o2, ctx, eo: handle_feedback(fb == "πŸ‘ Evo was correct. Retrain from this.", q, o1, o2, ctx, eo),
116
+ inputs=[feedback, question, option1, option2, context, evo_out],
 
117
  outputs=[feedback_status]
118
  )
119
 
120
  demo.launch()