Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,83 +59,105 @@ with gr.Blocks(theme=gr.themes.Base(), title="EvoRAG - Smarter Than GPT?") as de
|
|
59 |
demo.launch()'''
|
60 |
|
61 |
import gradio as gr
|
62 |
-
import torch
|
63 |
import os
|
64 |
from inference import get_evo_response, get_gpt_response
|
65 |
from logger import log_feedback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
os.makedirs(os.path.dirname(FEEDBACK_LOG_PATH), exist_ok=True) if os.path.dirname(FEEDBACK_LOG_PATH) else None
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
return "β
Feedback recorded. Evo will learn from this." if is_correct else "β
Feedback noted."
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
evo_ans, evo_reason, evo_conf, evo_ctx = get_evo_response(question, options, context)
|
84 |
-
gpt_ans = get_gpt_response(question, context)
|
85 |
-
|
86 |
-
evo_output = f"Evo's Suggestion: β
{evo_ans}\n\nWhy? {evo_reason}\n\nContext Used: {evo_ctx[:400]}..."
|
87 |
-
gpt_output = f"GPT-3.5's Suggestion: {gpt_ans}"
|
88 |
-
return evo_output, gpt_output, evo_ans
|
89 |
-
|
90 |
-
# β¬οΈ Interface
|
91 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
92 |
-
with gr.Column():
|
93 |
-
gr.Markdown(f"""
|
94 |
-
<div style='padding: 1em; border-radius: 12px; background: linear-gradient(90deg, #f0f4ff, #eef2fa); border: 1px solid #ccc;'>
|
95 |
-
<h1 style='font-size: 2em; font-weight: 800;'>π§ EvoRAG β General-Purpose Adaptive AI</h1>
|
96 |
-
<p><b>{EVO_VERSION}</b></p>
|
97 |
-
<p>Trained on reasoning tasks. Live learning from feedback. Combines architecture evolution and retrieval-augmented generation.</p>
|
98 |
-
<ul>
|
99 |
-
<li><b>Parameters:</b> {EVO_PARAMS}</li>
|
100 |
-
<li><b>Hardware:</b> {EVO_HARDWARE}</li>
|
101 |
-
<li><b>Live Feedback:</b> Logs every correction to evolve smarter.</li>
|
102 |
-
<li><b>Compare:</b> Evo vs GPT-3.5 on the same question.</li>
|
103 |
-
</ul>
|
104 |
-
<p style='font-style: italic; font-size: 0.9em;'>Built for ethical, explainable, and adaptive intelligence.</p>
|
105 |
-
</div>
|
106 |
-
""")
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
context = gr.Textbox(label="π Optional Context or Notes", placeholder="Paste any extra info here", lines=2)
|
114 |
|
|
|
|
|
115 |
with gr.Row():
|
116 |
-
|
117 |
-
gpt_out = gr.Textbox(label="π€ GPT-3.5's Suggestion")
|
118 |
-
|
119 |
-
evo_choice = gr.State()
|
120 |
-
|
121 |
with gr.Row():
|
122 |
-
|
|
|
|
|
123 |
|
|
|
124 |
with gr.Row():
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
131 |
|
132 |
-
|
|
|
133 |
|
|
|
134 |
submit_feedback.click(
|
135 |
-
fn=lambda fb, q, o1, o2, ctx, eo: handle_feedback(fb
|
136 |
-
inputs=[feedback, question, option1, option2, context,
|
137 |
-
outputs=[
|
138 |
)
|
|
|
139 |
|
140 |
-
demo.launch(
|
141 |
-
|
|
|
59 |
demo.launch()'''
|
60 |
|
61 |
import gradio as gr
|
|
|
62 |
import os
|
63 |
from inference import get_evo_response, get_gpt_response
|
64 |
from logger import log_feedback
|
65 |
+
import csv
|
66 |
+
import subprocess
|
67 |
+
|
68 |
+
# Helper to load Hall of Fame
|
69 |
+
def load_hall_of_fame():
|
70 |
+
entries = []
|
71 |
+
if os.path.exists("feedback_log.csv"):
|
72 |
+
with open("feedback_log.csv", newline='', encoding='utf-8') as f:
|
73 |
+
reader = csv.DictReader(f)
|
74 |
+
for row in reader:
|
75 |
+
try:
|
76 |
+
score = float(row.get("feedback", "0"))
|
77 |
+
if "π" in row["feedback"] or score > 0.85:
|
78 |
+
entries.append(row)
|
79 |
+
except:
|
80 |
+
continue
|
81 |
+
return entries[-10:][::-1] # last 10, reverse order
|
82 |
+
|
83 |
+
def handle_query(question, option1, option2, context):
|
84 |
+
options = [option1, option2]
|
85 |
+
evo_answer, evo_reasoning, evo_score, evo_context = get_evo_response(question, options, context)
|
86 |
+
gpt_answer = get_gpt_response(question, context)
|
87 |
+
return (
|
88 |
+
f"Answer: {evo_answer} (Confidence: {evo_score:.2f})\n\nReasoning: {evo_reasoning}\n\nContext used: {evo_context[:400]}...",
|
89 |
+
gpt_answer,
|
90 |
+
f"{question} | {context} | {evo_answer}"
|
91 |
+
)
|
92 |
|
93 |
+
def handle_feedback(feedback_text, question, option1, option2, context, evo_output):
|
94 |
+
is_helpful = "π" in feedback_text
|
95 |
+
log_feedback(question, context, evo_output, feedback_text)
|
96 |
+
return "β
Feedback logged and Evo will improve."
|
97 |
+
|
98 |
+
def trigger_retraining():
|
99 |
+
try:
|
100 |
+
subprocess.run(["python3", "retrain.py"], check=True)
|
101 |
+
return "β
Evo retrained from recent feedback!"
|
102 |
+
except Exception as e:
|
103 |
+
return f"β Retrain failed: {str(e)}"
|
104 |
+
|
105 |
+
def render_hof():
|
106 |
+
entries = load_hall_of_fame()
|
107 |
+
if not entries:
|
108 |
+
return "No Hall of Fame entries yet. Submit feedback!"
|
109 |
+
result = "\n\n".join(
|
110 |
+
[
|
111 |
+
f"π **Q:** {e['question']}\n**A:** {e['evo_answer']}\n**Feedback:** {e['feedback']}\n**Context:** {e['context'][:200]}..."
|
112 |
+
for e in entries
|
113 |
+
]
|
114 |
+
)
|
115 |
+
return result
|
116 |
|
117 |
+
description = """
|
118 |
+
# π§ EvoRAG β Adaptive Reasoning AI
|
|
|
119 |
|
120 |
+
**What is Evo?**
|
121 |
+
EvoTransformer is a lightweight, evolving neural network with ~28M parameters.
|
122 |
+
It learns from feedback, adapts over time, and reasons using both web and context data.
|
|
|
123 |
|
124 |
+
**Why Evo?**
|
125 |
+
Unlike GPT, Evo evolves from your interaction β architecture, weights, and logic. It's efficient, smart, and improvable on the fly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
+
**Hardware**: Trained on Google Colab CPU/GPU.
|
128 |
+
**Token limit**: 128.
|
129 |
+
**Benchmark**: PIQA, HellaSwag, ARC
|
130 |
+
**Version**: Evo v2.2 (Memory + Web Retrieval + Feedback Learning)
|
131 |
+
"""
|
|
|
132 |
|
133 |
+
with gr.Blocks(title="EvoRAG") as demo:
|
134 |
+
gr.Markdown(description)
|
135 |
with gr.Row():
|
136 |
+
question = gr.Textbox(label="π Ask anything", placeholder="e.g., Whatβs the best way to escape a house fire?")
|
|
|
|
|
|
|
|
|
137 |
with gr.Row():
|
138 |
+
option1 = gr.Textbox(label="Option A", placeholder="e.g., Run outside")
|
139 |
+
option2 = gr.Textbox(label="Option B", placeholder="e.g., Hide under bed")
|
140 |
+
context = gr.Textbox(label="π Optional Context", placeholder="Paste any extra background info here", lines=3)
|
141 |
|
142 |
+
submit_btn = gr.Button("π Run Comparison")
|
143 |
with gr.Row():
|
144 |
+
evo_output = gr.Textbox(label="π§ EvoRAG's Reasoned Answer", lines=6)
|
145 |
+
gpt_output = gr.Textbox(label="π€ GPT-3.5's Suggestion", lines=6)
|
146 |
+
|
147 |
+
feedback = gr.Radio(["π Evo was correct. Retrain from this.", "π Evo was wrong. Don't retrain."], label="Was Evoβs answer useful?", value=None)
|
148 |
+
submit_feedback = gr.Button("π¬ Submit Feedback")
|
149 |
+
retrain_button = gr.Button("π Retrain Evo Now")
|
150 |
+
feedback_status = gr.Textbox(label="Feedback Status", interactive=False)
|
151 |
|
152 |
+
with gr.Accordion("π Evo Hall of Fame (Top Reasoning Entries)", open=False):
|
153 |
+
hof_display = gr.Markdown(render_hof())
|
154 |
|
155 |
+
submit_btn.click(fn=handle_query, inputs=[question, option1, option2, context], outputs=[evo_output, gpt_output, feedback_status])
|
156 |
submit_feedback.click(
|
157 |
+
fn=lambda fb, q, o1, o2, ctx, eo: handle_feedback(fb, q, o1, o2, ctx, eo),
|
158 |
+
inputs=[feedback, question, option1, option2, context, feedback_status],
|
159 |
+
outputs=[feedback_status]
|
160 |
)
|
161 |
+
retrain_button.click(fn=trigger_retraining, inputs=[], outputs=[feedback_status])
|
162 |
|
163 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|