HemanM commited on
Commit
5da311e
Β·
verified Β·
1 Parent(s): 0a6b186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -30
app.py CHANGED
@@ -113,6 +113,7 @@ if __name__ == "__main__":
113
  demo.launch()
114
  '''
115
 
 
116
  # app.py
117
 
118
  import gradio as gr
@@ -129,15 +130,15 @@ from inference import (
129
  load_model,
130
  )
131
 
132
- FEEDBACK_LOG = "feedback_log.csv"
133
  GENOME_LOG = "genome_log.csv"
 
134
 
135
  # 🧠 Ask Evo
136
  def ask_evo(question, option1, option2, history, user_vote):
137
  options = [option1.strip(), option2.strip()]
138
  result = evo_chat_predict(history, question.strip(), options)
139
 
140
- # Create feedback_log.csv with headers if it doesn't exist
141
  if not os.path.exists(FEEDBACK_LOG):
142
  with open(FEEDBACK_LOG, "w", encoding="utf-8", newline="") as f:
143
  writer = csv.writer(f)
@@ -154,12 +155,10 @@ def ask_evo(question, option1, option2, history, user_vote):
154
  "vote": user_vote.strip() if user_vote else ""
155
  }
156
 
157
- # Log feedback
158
  with open(FEEDBACK_LOG, "a", newline='', encoding="utf-8") as f:
159
  writer = csv.DictWriter(f, fieldnames=row.keys())
160
  writer.writerow(row)
161
 
162
- # Prepare outputs
163
  evo_output = f"Answer: {row['evo_answer']} (Confidence: {row['confidence']})\n\nReasoning: {row['reasoning']}\n\nContext used: {row['context']}"
164
  gpt_output = get_gpt_response(question)
165
  history.append(row)
@@ -170,8 +169,20 @@ def ask_evo(question, option1, option2, history, user_vote):
170
  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', '?')}"
171
  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)"
172
 
173
- return evo_output, gpt_output, stats_text, sys_text, history, get_top_genomes()
 
174
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  # πŸ” Manual retrain button
177
  def retrain_evo():
@@ -185,28 +196,13 @@ def export_feedback():
185
  return pd.DataFrame()
186
  return pd.read_csv(FEEDBACK_LOG)
187
 
188
- # 🧹 Clear
189
  def clear_all():
190
- return "", "", "", "", [], None, pd.DataFrame()
191
 
192
- # πŸ† Load top genomes
193
- def get_top_genomes(n=5):
194
- if os.path.exists(GENOME_LOG):
195
- df = pd.read_csv(GENOME_LOG)
196
-
197
- # πŸ›‘ Check if 'score' column exists
198
- if "score" in df.columns:
199
- df = df.sort_values(by="score", ascending=False).head(n)
200
- return df.reset_index(drop=True)
201
- else:
202
- return pd.DataFrame({"error": ["No 'score' column in genome_log.csv"]})
203
- else:
204
- return pd.DataFrame({"error": ["No genome_log.csv found"]})
205
-
206
-
207
- # πŸ–ΌοΈ UI
208
  with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
209
- 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.")
210
 
211
  with gr.Row():
212
  question = gr.Textbox(label="🧠 Your Question", placeholder="e.g. Why is the sky blue?")
@@ -222,9 +218,10 @@ with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
222
 
223
  with gr.Row():
224
  stats = gr.Textbox(label="πŸ“Š Evo Stats")
225
- system = gr.Textbox(label="πŸ”΅ Status")
 
 
226
 
227
- evo_radio = gr.Radio(["Evo", "GPT"], label="🧠 Who was better?", info="Optional – fuels evolution")
228
  history = gr.State([])
229
 
230
  with gr.Row():
@@ -234,13 +231,27 @@ with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
234
  export_btn = gr.Button("πŸ“€ Export Feedback CSV")
235
 
236
  export_table = gr.Dataframe(label="πŸ“œ Conversation History")
237
- genome_table = gr.Dataframe(label="πŸ† Hall of Fame – Top Genomes")
 
 
 
 
 
 
238
 
239
- ask_btn.click(fn=ask_evo, inputs=[question, option1, option2, history, evo_radio],
240
- outputs=[evo_ans, gpt_ans, stats, system, history, genome_table])
241
  retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[stats])
242
- clear_btn.click(fn=clear_all, inputs=[], outputs=[question, option1, option2, evo_ans, gpt_ans, stats, system, history, genome_table])
 
 
 
 
 
 
 
 
 
243
  export_btn.click(fn=export_feedback, inputs=[], outputs=[export_table])
244
 
245
  if __name__ == "__main__":
246
  demo.launch()
 
 
113
  demo.launch()
114
  '''
115
 
116
+ # app.py
117
  # app.py
118
 
119
  import gradio as gr
 
130
  load_model,
131
  )
132
 
 
133
  GENOME_LOG = "genome_log.csv"
134
+ FEEDBACK_LOG = "feedback_log.csv"
135
 
136
  # 🧠 Ask Evo
137
  def ask_evo(question, option1, option2, history, user_vote):
138
  options = [option1.strip(), option2.strip()]
139
  result = evo_chat_predict(history, question.strip(), options)
140
 
141
+ # Create feedback_log.csv if it doesn't exist
142
  if not os.path.exists(FEEDBACK_LOG):
143
  with open(FEEDBACK_LOG, "w", encoding="utf-8", newline="") as f:
144
  writer = csv.writer(f)
 
155
  "vote": user_vote.strip() if user_vote else ""
156
  }
157
 
 
158
  with open(FEEDBACK_LOG, "a", newline='', encoding="utf-8") as f:
159
  writer = csv.DictWriter(f, fieldnames=row.keys())
160
  writer.writerow(row)
161
 
 
162
  evo_output = f"Answer: {row['evo_answer']} (Confidence: {row['confidence']})\n\nReasoning: {row['reasoning']}\n\nContext used: {row['context']}"
163
  gpt_output = get_gpt_response(question)
164
  history.append(row)
 
169
  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', '?')}"
170
  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)"
171
 
172
+ genome_df = get_top_genomes()
173
+ return evo_output, gpt_output, stats_text, sys_text, history, genome_df
174
 
175
+ # πŸ“Š Top genome stats
176
+ def get_top_genomes(n=5):
177
+ if not os.path.exists(GENOME_LOG):
178
+ return pd.DataFrame()
179
+ try:
180
+ df = pd.read_csv(GENOME_LOG)
181
+ if "score" in df.columns:
182
+ df = df.sort_values(by="score", ascending=False)
183
+ return df.tail(n)
184
+ except Exception:
185
+ return pd.DataFrame()
186
 
187
  # πŸ” Manual retrain button
188
  def retrain_evo():
 
196
  return pd.DataFrame()
197
  return pd.read_csv(FEEDBACK_LOG)
198
 
199
+ # 🧹 Clear UI
200
  def clear_all():
201
+ return "", "", "", "", "", "", pd.DataFrame(), {}, pd.DataFrame()
202
 
203
+ # πŸ–ΌοΈ UI Layout
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
205
+ gr.Markdown("## πŸš€ Evo is not just another AI. It evolves. It learns from you. It mutates based on feedback.\n\nNo retraining labs. No frozen weights. This is live reasoning meets evolution.")
206
 
207
  with gr.Row():
208
  question = gr.Textbox(label="🧠 Your Question", placeholder="e.g. Why is the sky blue?")
 
218
 
219
  with gr.Row():
220
  stats = gr.Textbox(label="πŸ“Š Evo Stats")
221
+ system = gr.Textbox(label="πŸ”΅ System Status")
222
+
223
+ evo_radio = gr.Radio(["Evo", "GPT"], label="🧠 Who was better?", info="Optional – leave blank if both were wrong")
224
 
 
225
  history = gr.State([])
226
 
227
  with gr.Row():
 
231
  export_btn = gr.Button("πŸ“€ Export Feedback CSV")
232
 
233
  export_table = gr.Dataframe(label="πŸ“œ Conversation History")
234
+ genome_table = gr.Dataframe(label="🧬 Top Genomes")
235
+
236
+ ask_btn.click(
237
+ fn=ask_evo,
238
+ inputs=[question, option1, option2, history, evo_radio],
239
+ outputs=[evo_ans, gpt_ans, stats, system, history, genome_table]
240
+ )
241
 
 
 
242
  retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[stats])
243
+
244
+ clear_btn.click(
245
+ fn=clear_all,
246
+ inputs=[],
247
+ outputs=[
248
+ question, option1, option2, evo_ans, gpt_ans,
249
+ stats, export_table, system, genome_table
250
+ ]
251
+ )
252
+
253
  export_btn.click(fn=export_feedback, inputs=[], outputs=[export_table])
254
 
255
  if __name__ == "__main__":
256
  demo.launch()
257
+