Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 69 |
-
if
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
**
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 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="
|
| 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 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
with gr.Column():
|
| 118 |
-
gr.Markdown("
|
| 119 |
-
|
| 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 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 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()
|
|
|