Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,26 +34,27 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
34 |
|
35 |
convo = gr.Dataframe(headers=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"], interactive=False, wrap=True, label="📜 Conversation History")
|
36 |
|
|
|
37 |
def ask_evo(q, opt1, opt2, hist):
|
38 |
result = evo_chat_predict(hist, q, [opt1, opt2])
|
39 |
evo_text = f"Answer: {result['answer']} (Confidence: {result['confidence']})\n\nReasoning: {result['reasoning']}"
|
40 |
-
|
41 |
-
gpt_box.update(value=get_gpt_response(q))
|
42 |
stats = get_model_config()
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
|
|
46 |
def retrain_evo():
|
47 |
-
|
48 |
|
|
|
49 |
def clear_fields():
|
50 |
-
|
51 |
-
option1.update(value="")
|
52 |
-
option2.update(value="")
|
53 |
-
evo_box.update(value="")
|
54 |
-
gpt_box.update(value="")
|
55 |
-
status_box.update(value="")
|
56 |
|
|
|
57 |
def log_feedback_to_csv():
|
58 |
if feedback_log:
|
59 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
@@ -62,14 +63,20 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
62 |
writer = csv.writer(f)
|
63 |
writer.writerow(["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
64 |
writer.writerows(feedback_log)
|
65 |
-
|
66 |
else:
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
demo.launch()
|
|
|
34 |
|
35 |
convo = gr.Dataframe(headers=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"], interactive=False, wrap=True, label="📜 Conversation History")
|
36 |
|
37 |
+
# 🔍 Ask Evo
|
38 |
def ask_evo(q, opt1, opt2, hist):
|
39 |
result = evo_chat_predict(hist, q, [opt1, opt2])
|
40 |
evo_text = f"Answer: {result['answer']} (Confidence: {result['confidence']})\n\nReasoning: {result['reasoning']}"
|
41 |
+
gpt_text = get_gpt_response(q)
|
|
|
42 |
stats = get_model_config()
|
43 |
+
stats_text = f"Layers: {stats['num_layers']} | Heads: {stats['num_heads']} | FFN: {stats['ffn_dim']} | Memory: {stats['memory_enabled']} | Phase: {stats['phase']} | Accuracy: {stats['accuracy']}"
|
44 |
+
# Update conversation history
|
45 |
+
new_row = [q, opt1, opt2, result["answer"], result["confidence"], result["reasoning"], result["context_used"]]
|
46 |
+
updated_df = pd.concat([hist, pd.DataFrame([new_row], columns=hist.columns)], ignore_index=True)
|
47 |
+
return evo_text, gpt_text, stats_text, updated_df
|
48 |
|
49 |
+
# 🧠 Simulated retraining
|
50 |
def retrain_evo():
|
51 |
+
return "Retraining Evo... (simulated)"
|
52 |
|
53 |
+
# 🧹 Clear UI
|
54 |
def clear_fields():
|
55 |
+
return "", "", "", "", "", pd.DataFrame(columns=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
# 📤 Export feedback
|
58 |
def log_feedback_to_csv():
|
59 |
if feedback_log:
|
60 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
63 |
writer = csv.writer(f)
|
64 |
writer.writerow(["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
65 |
writer.writerows(feedback_log)
|
66 |
+
return f"✅ Feedback exported to {filepath}"
|
67 |
else:
|
68 |
+
return "⚠️ No feedback to export."
|
69 |
|
70 |
+
# 🔘 Event bindings
|
71 |
+
evo_btn.click(
|
72 |
+
fn=ask_evo,
|
73 |
+
inputs=[query, option1, option2, convo],
|
74 |
+
outputs=[evo_box, gpt_box, evo_stats, convo]
|
75 |
+
)
|
76 |
+
|
77 |
+
retrain_btn.click(fn=retrain_evo, outputs=[status_box])
|
78 |
+
clear_btn.click(fn=clear_fields, outputs=[query, option1, option2, evo_box, gpt_box, convo])
|
79 |
+
export_btn.click(fn=log_feedback_to_csv, outputs=[status_box])
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
demo.launch()
|