Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,134 +1,90 @@
|
|
1 |
import gradio as gr
|
2 |
-
from inference import evo_chat_predict, get_gpt_response, get_model_config
|
3 |
-
from logger import log_feedback
|
4 |
-
import subprocess
|
5 |
import os
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
if len(lines) > 1:
|
60 |
-
last = lines[-1].strip().split(",")
|
61 |
-
log_txt = f"𧬠Genome ID: {last[0]} | Accuracy: {last[-1]}"
|
62 |
-
|
63 |
-
return evo_msg, chat_history, config_str, log_txt, why_evo_panel()
|
64 |
-
|
65 |
-
# π§ Static "Why Evo?" panel
|
66 |
-
def why_evo_panel():
|
67 |
-
return (
|
68 |
-
"### π Why Evo?\n"
|
69 |
-
"- Learns from your input β evolves in real time\n"
|
70 |
-
"- Adaptive architecture (changes #layers, memory, etc.)\n"
|
71 |
-
"- Tiny model (~13Mβ28M params) vs GPT-3.5 (175B)\n"
|
72 |
-
"- Runs on CPU or low-end GPUs\n"
|
73 |
-
"- Transparent architecture: shows how it thinks\n"
|
74 |
-
"- Can be deployed, fine-tuned, and evolved per user/domain"
|
75 |
-
)
|
76 |
-
|
77 |
-
# π Clear everything
|
78 |
-
def clear_fn():
|
79 |
-
global chat_history
|
80 |
-
chat_history = []
|
81 |
-
return "", "", "", None, [], "", ""
|
82 |
-
|
83 |
-
# π Retrain
|
84 |
-
def retrain_model():
|
85 |
-
try:
|
86 |
-
subprocess.run(["python", "retrain_from_feedback.py"], check=True)
|
87 |
-
return "β
Evo retrained successfully."
|
88 |
-
except Exception as e:
|
89 |
-
return f"β Retraining failed: {str(e)}"
|
90 |
-
|
91 |
-
# β¬οΈ Download feedback
|
92 |
-
def export_feedback():
|
93 |
-
if os.path.exists("feedback_log.csv"):
|
94 |
-
return "feedback_log.csv"
|
95 |
-
return None
|
96 |
|
97 |
-
# π Gradio UI
|
98 |
-
with gr.Blocks(title="EvoRAG β Real-Time Adaptive Reasoning AI", css="body { font-family: 'Segoe UI', sans-serif; background-color: #f8f9fa; }") as demo:
|
99 |
with gr.Row():
|
100 |
-
with gr.Column(
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
option2 = gr.Textbox(label="Option 2")
|
111 |
-
user_vote = gr.Radio(["Evo", "GPT"], label="π³οΈ Who was better?", info="Optional β fuels evolution")
|
112 |
-
with gr.Row():
|
113 |
-
submit = gr.Button("π§ Ask Evo")
|
114 |
-
clear = gr.Button("π Clear")
|
115 |
-
with gr.Row():
|
116 |
-
retrain = gr.Button("π Retrain Evo")
|
117 |
-
export = gr.Button("β¬οΈ Export Feedback CSV")
|
118 |
|
119 |
with gr.Row():
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
model_info = gr.Markdown(label="π§ Evo Architecture")
|
125 |
-
genome_log = gr.Markdown(label="π Evolution Log")
|
126 |
-
evo_why = gr.Markdown(label="π¬ Why Evo?")
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
export.click(export_feedback, outputs=[])
|
133 |
|
134 |
-
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
import os
|
3 |
+
from inference import evo_infer, gpt_infer
|
4 |
+
from retrain_from_feedback import train_evo
|
5 |
+
from logger import log_feedback
|
6 |
|
7 |
+
question = gr.Textbox(label="π§ Your Question", placeholder="e.g. What should you do if there's a fire?", lines=1)
|
8 |
+
option1 = gr.Textbox(label="π
°οΈ Option 1", placeholder="Enter the first option")
|
9 |
+
option2 = gr.Textbox(label="π
±οΈ Option 2", placeholder="Enter the second option")
|
10 |
+
choice = gr.Radio(["Evo", "GPT"], label="π³οΈ Who was better?", info="Optional β fuels evolution", type="value")
|
11 |
+
|
12 |
+
evo_out = gr.Textbox(label="π€ Evo", interactive=False)
|
13 |
+
gpt_out = gr.Textbox(label="π§ GPT-3.5", interactive=False)
|
14 |
+
history = gr.Textbox(label="π Conversation History", interactive=False)
|
15 |
+
evo_stats = gr.Textbox(label="π Evo Stats", value="Layers: 6 | Heads: 8 | FFN: 1024 | Memory: β
| Accuracy: ~64.5% | Phase: v2.2", interactive=False)
|
16 |
+
|
17 |
+
def run_inference(q, o1, o2, winner):
|
18 |
+
evo_answer, evo_reasoning = evo_infer(q, o1, o2)
|
19 |
+
gpt_answer = gpt_infer(q, o1, o2)
|
20 |
+
context = f"Question: {q}\nOptions: {o1}, {o2}"
|
21 |
+
log_feedback(q, o1, o2, context, evo_answer, gpt_answer, evo_reasoning, winner)
|
22 |
+
conv_log = f"π€ {q}\nπ
°οΈ {o1} | π
±οΈ {o2}\nπ€ Evo: {evo_answer} ({evo_reasoning})\nπ§ GPT: {gpt_answer}"
|
23 |
+
return evo_answer, gpt_answer, conv_log
|
24 |
+
|
25 |
+
def clear():
|
26 |
+
return "", "", "", None, "", "", ""
|
27 |
+
|
28 |
+
def export_csv():
|
29 |
+
return gr.File("feedback_log.csv")
|
30 |
+
|
31 |
+
def retrain():
|
32 |
+
train_evo()
|
33 |
+
return "π Evo model reloaded."
|
34 |
+
|
35 |
+
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
36 |
+
body { background-color: #f3f6fb; font-family: 'Segoe UI', sans-serif; }
|
37 |
+
.gradio-container { max-width: 1024px; margin: auto; }
|
38 |
+
.gr-box { box-shadow: 0 4px 16px rgba(0,0,0,0.1); border-radius: 12px; padding: 16px; transition: all 0.3s ease-in-out; }
|
39 |
+
.gr-button { border-radius: 8px; font-weight: 600; transition: all 0.2s ease-in-out; }
|
40 |
+
.gr-button:hover { transform: scale(1.03); background-color: #e6f2ff; }
|
41 |
+
.gr-textbox, .gr-radio { border-radius: 8px; }
|
42 |
+
""") as demo:
|
43 |
+
|
44 |
+
gr.Markdown("""
|
45 |
+
<h1 style="font-size: 2.2em;">π§ EvoRAG β Real-Time Reasoning AI</h1>
|
46 |
+
<p><b>Built Different. Learns Live. Evolves from You.</b></p>
|
47 |
+
<div style="margin-top: 10px; font-size: 0.9em;">
|
48 |
+
<ul>
|
49 |
+
<li>π <b>Why Evo?</b></li>
|
50 |
+
<li>βοΈ Learns from your input β evolves in real time</li>
|
51 |
+
<li>βοΈ Adaptive architecture (changes #layers, memory, etc.)</li>
|
52 |
+
<li>βοΈ Tiny model (~13Mβ28M params) vs GPT-3.5 (175B)</li>
|
53 |
+
<li>βοΈ Runs on CPU or low-end GPUs</li>
|
54 |
+
<li>βοΈ Transparent architecture: shows how it thinks</li>
|
55 |
+
<li>βοΈ Can be deployed, fine-tuned, and evolved per user/domain</li>
|
56 |
+
</ul>
|
57 |
+
</div>
|
58 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
|
|
|
|
60 |
with gr.Row():
|
61 |
+
with gr.Column():
|
62 |
+
question.render()
|
63 |
+
option1.render()
|
64 |
+
option2.render()
|
65 |
+
choice.render()
|
66 |
+
|
67 |
+
with gr.Column():
|
68 |
+
ask_btn = gr.Button("π‘ Ask Evo", variant="primary")
|
69 |
+
retrain_btn = gr.Button("π Retrain Evo")
|
70 |
+
clear_btn = gr.Button("π§Ή Clear")
|
71 |
+
export_btn = gr.Button("β¬οΈ Export Feedback CSV")
|
72 |
+
evo_stats.render()
|
73 |
|
74 |
+
with gr.Row():
|
75 |
+
evo_out.render()
|
76 |
+
gpt_out.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
with gr.Row():
|
79 |
+
retrain_status = gr.Textbox(label="π Status", interactive=False)
|
80 |
+
|
81 |
+
with gr.Accordion("π Conversation History", open=True):
|
82 |
+
history.render()
|
|
|
|
|
|
|
83 |
|
84 |
+
ask_btn.click(fn=run_inference, inputs=[question, option1, option2, choice], outputs=[evo_out, gpt_out, history])
|
85 |
+
clear_btn.click(fn=clear, outputs=[question, option1, option2, choice, evo_out, gpt_out, history])
|
86 |
+
export_btn.click(fn=export_csv, outputs=[])
|
87 |
+
retrain_btn.click(fn=retrain, outputs=[retrain_status])
|
|
|
88 |
|
89 |
+
if __name__ == "__main__":
|
90 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|