Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from inference import evo_chat_predict, get_model_config, get_system_stats, get_gpt_response
|
3 |
import pandas as pd
|
4 |
import csv
|
5 |
-
import os
|
6 |
from datetime import datetime
|
7 |
-
from inference import retrain_from_feedback
|
8 |
-
|
9 |
|
10 |
feedback_log = []
|
11 |
|
@@ -19,7 +16,7 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
19 |
|
20 |
with gr.Row():
|
21 |
with gr.Column():
|
22 |
-
query = gr.Textbox(label="π§ Your Question", placeholder="e.g. What should you do if thereβs a fire?"
|
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)
|
@@ -34,7 +31,10 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
34 |
gpt_box = gr.Textbox(label="π€ GPT-3.5", interactive=False)
|
35 |
status_box = gr.Textbox(label="π΅ Status", interactive=False)
|
36 |
|
37 |
-
convo = gr.Dataframe(
|
|
|
|
|
|
|
38 |
|
39 |
# π Ask Evo
|
40 |
def ask_evo(q, opt1, opt2, hist):
|
@@ -43,19 +43,18 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
43 |
gpt_text = get_gpt_response(q)
|
44 |
stats = get_model_config()
|
45 |
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']}"
|
46 |
-
# Update conversation history
|
47 |
new_row = [q, opt1, opt2, result["answer"], result["confidence"], result["reasoning"], result["context_used"]]
|
48 |
updated_df = pd.concat([hist, pd.DataFrame([new_row], columns=hist.columns)], ignore_index=True)
|
49 |
return evo_text, gpt_text, stats_text, updated_df
|
50 |
|
51 |
-
#
|
52 |
def retrain_evo():
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
# π§Ή Clear UI
|
58 |
def clear_fields():
|
|
|
59 |
return "", "", "", "", "", pd.DataFrame(columns=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
60 |
|
61 |
# π€ Export feedback
|
@@ -72,15 +71,10 @@ with gr.Blocks(theme=gr.themes.Base(), css="body { background-color: #0f0f0f; co
|
|
72 |
return "β οΈ No feedback to export."
|
73 |
|
74 |
# π Event bindings
|
75 |
-
evo_btn.click(
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
)
|
80 |
-
|
81 |
-
retrain_btn.click(fn=retrain_evo, outputs=[status_box])
|
82 |
-
clear_btn.click(fn=clear_fields, outputs=[query, option1, option2, evo_box, gpt_box, convo])
|
83 |
-
export_btn.click(fn=log_feedback_to_csv, outputs=[status_box])
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from inference import evo_chat_predict, get_model_config, get_system_stats, get_gpt_response, retrain_from_feedback
|
3 |
import pandas as pd
|
4 |
import csv
|
|
|
5 |
from datetime import datetime
|
|
|
|
|
6 |
|
7 |
feedback_log = []
|
8 |
|
|
|
16 |
|
17 |
with gr.Row():
|
18 |
with gr.Column():
|
19 |
+
query = gr.Textbox(label="π§ Your Question", placeholder="e.g. What should you do if thereβs a fire?")
|
20 |
option1 = gr.Textbox(label="β Option 1", placeholder="Enter the first option")
|
21 |
option2 = gr.Textbox(label="β Option 2", placeholder="Enter the second option")
|
22 |
feedback = gr.Radio(["Evo", "GPT"], label="π§ Who was better?", info="Optional β fuels evolution", interactive=True)
|
|
|
31 |
gpt_box = gr.Textbox(label="π€ GPT-3.5", interactive=False)
|
32 |
status_box = gr.Textbox(label="π΅ Status", interactive=False)
|
33 |
|
34 |
+
convo = gr.Dataframe(
|
35 |
+
headers=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"],
|
36 |
+
interactive=False, wrap=True, label="π Conversation History"
|
37 |
+
)
|
38 |
|
39 |
# π Ask Evo
|
40 |
def ask_evo(q, opt1, opt2, hist):
|
|
|
43 |
gpt_text = get_gpt_response(q)
|
44 |
stats = get_model_config()
|
45 |
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']}"
|
|
|
46 |
new_row = [q, opt1, opt2, result["answer"], result["confidence"], result["reasoning"], result["context_used"]]
|
47 |
updated_df = pd.concat([hist, pd.DataFrame([new_row], columns=hist.columns)], ignore_index=True)
|
48 |
return evo_text, gpt_text, stats_text, updated_df
|
49 |
|
50 |
+
# π Actual retraining
|
51 |
def retrain_evo():
|
52 |
+
status = retrain_from_feedback(feedback_log)
|
53 |
+
return status
|
|
|
54 |
|
55 |
# π§Ή Clear UI
|
56 |
def clear_fields():
|
57 |
+
feedback_log.clear()
|
58 |
return "", "", "", "", "", pd.DataFrame(columns=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"])
|
59 |
|
60 |
# π€ Export feedback
|
|
|
71 |
return "β οΈ No feedback to export."
|
72 |
|
73 |
# π Event bindings
|
74 |
+
evo_btn.click(fn=ask_evo, inputs=[query, option1, option2, convo], outputs=[evo_box, gpt_box, evo_stats, convo])
|
75 |
+
retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[status_box])
|
76 |
+
clear_btn.click(fn=clear_fields, inputs=[], outputs=[query, option1, option2, evo_box, gpt_box, convo])
|
77 |
+
export_btn.click(fn=log_feedback_to_csv, inputs=[], outputs=[status_box])
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
demo.launch()
|