HemanM commited on
Commit
af12592
Β·
verified Β·
1 Parent(s): 7e4494b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
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?", lines=1)
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(headers=["Question", "Option 1", "Option 2", "Answer", "Confidence", "Reasoning", "Context"], interactive=False, wrap=True, label="πŸ“œ Conversation History")
 
 
 
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
- # 🧠 Simulated retraining
52
  def retrain_evo():
53
- status = retrain_from_feedback(feedback_log)
54
- return status
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
- fn=ask_evo,
77
- inputs=[query, option1, option2, convo],
78
- outputs=[evo_box, gpt_box, evo_stats, convo]
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()