Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,101 +1,109 @@
|
|
1 |
import gradio as gr
|
2 |
-
from inference import evo_chat_predict, get_model_config, get_gpt_response, load_model
|
3 |
import pandas as pd
|
4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import os
|
6 |
-
|
7 |
-
from inference import retrain_from_feedback_csv as train_evo
|
8 |
-
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
with gr.
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
</div>
|
18 |
-
""")
|
19 |
|
20 |
with gr.Row():
|
21 |
with gr.Column():
|
22 |
-
|
23 |
-
option1 = gr.Textbox(label="β Option 1", placeholder="Enter the first option")
|
24 |
-
option2 = gr.Textbox(label="β Option 2", placeholder="Enter the second option")
|
25 |
-
feedback = gr.Radio(["Evo", "GPT"], label="π§ Who was better?", info="Optional β fuels evolution", interactive=True)
|
26 |
-
evo_btn = gr.Button("β‘ Ask Evo", elem_id="evo-btn")
|
27 |
-
retrain_btn = gr.Button("π Retrain Evo", elem_id="retrain-btn")
|
28 |
-
clear_btn = gr.Button("π§Ή Clear")
|
29 |
-
export_btn = gr.Button("π€ Export Feedback CSV")
|
30 |
-
|
31 |
with gr.Column():
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
# Log feedback
|
56 |
-
if selected in ["Evo", "GPT"]:
|
57 |
-
feedback_log.append(new_row + [selected, "yes" if selected == "Evo" else "no"])
|
58 |
-
|
59 |
-
return evo_text, gpt_text, stats_text, updated_df
|
60 |
-
|
61 |
-
# π Retrain Evo
|
62 |
-
def retrain_evo():
|
63 |
-
if not feedback_log:
|
64 |
-
return "β οΈ No feedback data to retrain from."
|
65 |
-
|
66 |
-
with open("feedback_log.csv", "w", newline="") as f:
|
67 |
-
writer = csv.writer(f)
|
68 |
-
writer.writerow(["question", "option1", "option2", "answer", "confidence", "reasoning", "context", "user_preference", "evo_was_correct"])
|
69 |
-
for row in feedback_log:
|
70 |
-
writer.writerow(row)
|
71 |
-
|
72 |
-
train_evo()
|
73 |
-
load_model()
|
74 |
-
return f"β
Evo retrained on {len(feedback_log)} entries and reloaded."
|
75 |
-
|
76 |
-
# π§Ή Clear UI
|
77 |
-
def clear_fields():
|
78 |
-
feedback_log.clear()
|
79 |
-
return "", "", "", "", "", pd.DataFrame(columns=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
80 |
-
|
81 |
-
# π€ Export feedback
|
82 |
-
def log_feedback_to_csv():
|
83 |
-
if feedback_log:
|
84 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
85 |
-
filepath = f"feedback_{timestamp}.csv"
|
86 |
-
with open(filepath, "w", newline="") as f:
|
87 |
-
writer = csv.writer(f)
|
88 |
-
writer.writerow(["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context", "User Pref", "Evo Correct"])
|
89 |
-
writer.writerows(feedback_log)
|
90 |
-
return f"β
Feedback exported to {filepath}"
|
91 |
-
else:
|
92 |
-
return "β οΈ No feedback to export."
|
93 |
-
|
94 |
-
# π Event bindings
|
95 |
-
evo_btn.click(fn=ask_evo, inputs=[query, option1, option2, convo, feedback], outputs=[evo_box, gpt_box, evo_stats, convo])
|
96 |
-
retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[status_box])
|
97 |
-
clear_btn.click(fn=clear_fields, inputs=[], outputs=[query, option1, option2, evo_box, gpt_box, convo])
|
98 |
-
export_btn.click(fn=log_feedback_to_csv, inputs=[], outputs=[status_box])
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import pandas as pd
|
3 |
+
from inference import (
|
4 |
+
evo_chat_predict,
|
5 |
+
get_gpt_response,
|
6 |
+
get_model_config,
|
7 |
+
get_system_stats,
|
8 |
+
retrain_from_feedback_csv,
|
9 |
+
load_model,
|
10 |
+
)
|
11 |
import os
|
12 |
+
import csv
|
|
|
|
|
13 |
|
14 |
+
FEEDBACK_LOG = "feedback_log.csv"
|
15 |
+
|
16 |
+
# π§ Ask Evo
|
17 |
+
def ask_evo(question, option1, option2, history):
|
18 |
+
options = [option1.strip(), option2.strip()]
|
19 |
+
result = evo_chat_predict(history, question.strip(), options)
|
20 |
+
|
21 |
+
row = {
|
22 |
+
"question": question.strip(),
|
23 |
+
"option1": option1.strip(),
|
24 |
+
"option2": option2.strip(),
|
25 |
+
"evo_answer": result["answer"],
|
26 |
+
"confidence": result["confidence"],
|
27 |
+
"reasoning": result["reasoning"],
|
28 |
+
"context": result["context_used"]
|
29 |
+
}
|
30 |
+
|
31 |
+
# Log feedback
|
32 |
+
file_exists = os.path.exists(FEEDBACK_LOG)
|
33 |
+
with open(FEEDBACK_LOG, "a", newline='', encoding="utf-8") as f:
|
34 |
+
writer = csv.DictWriter(f, fieldnames=row.keys())
|
35 |
+
if not file_exists:
|
36 |
+
writer.writeheader()
|
37 |
+
writer.writerow(row)
|
38 |
+
|
39 |
+
# Prepare outputs
|
40 |
+
evo_output = f"Answer: {row['evo_answer']} (Confidence: {row['confidence']})\n\nReasoning: {row['reasoning']}\n\nContext used: {row['context']}"
|
41 |
+
gpt_output = get_gpt_response(question)
|
42 |
+
history.append(row)
|
43 |
+
|
44 |
+
stats = get_model_config()
|
45 |
+
sys_stats = get_system_stats()
|
46 |
+
|
47 |
+
# β
FIXED PHASE ERROR HERE
|
48 |
+
stats_text = f"Layers: {stats.get('num_layers', '?')} | Heads: {stats.get('num_heads', '?')} | FFN: {stats.get('ffn_dim', '?')} | Memory: {stats.get('memory_enabled', '?')} | Accuracy: {stats.get('accuracy', '?')}"
|
49 |
+
|
50 |
+
sys_text = f"Device: {sys_stats['device']} | CPU: {sys_stats['cpu_usage_percent']}% | RAM: {sys_stats['memory_used_gb']}GB / {sys_stats['memory_total_gb']}GB | GPU: {sys_stats['gpu_name']} ({sys_stats['gpu_memory_used_gb']}GB / {sys_stats['gpu_memory_total_gb']}GB)"
|
51 |
+
|
52 |
+
return evo_output, gpt_output, stats_text, sys_text, history
|
53 |
+
|
54 |
+
# π Manual retrain button
|
55 |
+
def retrain_evo():
|
56 |
+
msg = retrain_from_feedback_csv()
|
57 |
+
load_model(force_reload=True)
|
58 |
+
return msg
|
59 |
+
|
60 |
+
# π€ Export feedback
|
61 |
+
def export_feedback():
|
62 |
+
if not os.path.exists(FEEDBACK_LOG):
|
63 |
+
return pd.DataFrame()
|
64 |
+
return pd.read_csv(FEEDBACK_LOG)
|
65 |
+
|
66 |
+
# π§Ή Clear
|
67 |
+
def clear_all():
|
68 |
+
return "", "", "", "", []
|
69 |
+
|
70 |
+
# πΌοΈ UI
|
71 |
+
with gr.Blocks(title="π§ Evo β Reasoning AI") as demo:
|
72 |
+
gr.Markdown("## Why Evo? π Evo is not just another AI. It evolves. It learns from you. It adapts its architecture live based on feedback.\n\nNo retraining labs, no frozen weights. This is live reasoning meets evolution. Built to outperform, built to survive.")
|
73 |
|
74 |
+
with gr.Row():
|
75 |
+
question = gr.Textbox(label="π§ Your Question", placeholder="e.g. Why is the sky blue?")
|
76 |
+
with gr.Row():
|
77 |
+
option1 = gr.Textbox(label="β Option 1")
|
78 |
+
option2 = gr.Textbox(label="β Option 2")
|
|
|
|
|
79 |
|
80 |
with gr.Row():
|
81 |
with gr.Column():
|
82 |
+
evo_ans = gr.Textbox(label="π§ Evo", lines=6)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
with gr.Column():
|
84 |
+
gpt_ans = gr.Textbox(label="π€ GPT-3.5", lines=6)
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
stats = gr.Textbox(label="π Evo Stats")
|
88 |
+
system = gr.Textbox(label="π΅ Status")
|
89 |
+
|
90 |
+
with gr.Row():
|
91 |
+
evo_radio = gr.Radio(["Evo", "GPT"], label="π§ Who was better?", info="Optional β fuels evolution")
|
92 |
+
|
93 |
+
history = gr.State([])
|
94 |
+
|
95 |
+
with gr.Row():
|
96 |
+
ask_btn = gr.Button("β‘ Ask Evo")
|
97 |
+
retrain_btn = gr.Button("π Retrain Evo")
|
98 |
+
clear_btn = gr.Button("π§Ή Clear")
|
99 |
+
export_btn = gr.Button("π€ Export Feedback CSV")
|
100 |
+
|
101 |
+
export_table = gr.Dataframe(label="π Conversation History")
|
102 |
+
|
103 |
+
ask_btn.click(fn=ask_evo, inputs=[question, option1, option2, history], outputs=[evo_ans, gpt_ans, stats, system, history])
|
104 |
+
retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[stats])
|
105 |
+
clear_btn.click(fn=clear_all, inputs=[], outputs=[question, option1, option2, evo_ans, gpt_ans, stats, system, history])
|
106 |
+
export_btn.click(fn=export_feedback, inputs=[], outputs=[export_table])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
if __name__ == "__main__":
|
109 |
demo.launch()
|