HemanM commited on
Commit
0657895
Β·
verified Β·
1 Parent(s): 4eec51c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -1
app.py CHANGED
@@ -1,6 +1,6 @@
1
  # app.py
2
 
3
- import gradio as gr
4
  import pandas as pd
5
  from inference import (
6
  evo_chat_predict,
@@ -111,3 +111,130 @@ with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
111
 
112
  if __name__ == "__main__":
113
  demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # app.py
2
 
3
+ '''import gradio as gr
4
  import pandas as pd
5
  from inference import (
6
  evo_chat_predict,
 
111
 
112
  if __name__ == "__main__":
113
  demo.launch()
114
+ '''
115
+
116
+ # app.py
117
+
118
+ import gradio as gr
119
+ import pandas as pd
120
+ import os
121
+ import csv
122
+
123
+ from inference import (
124
+ evo_chat_predict,
125
+ get_gpt_response,
126
+ get_model_config,
127
+ get_system_stats,
128
+ retrain_from_feedback_csv,
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)
144
+ writer.writerow(["question", "option1", "option2", "evo_answer", "confidence", "reasoning", "context", "vote"])
145
+
146
+ row = {
147
+ "question": question.strip(),
148
+ "option1": option1.strip(),
149
+ "option2": option2.strip(),
150
+ "evo_answer": result["answer"],
151
+ "confidence": result["confidence"],
152
+ "reasoning": result["reasoning"],
153
+ "context": result["context_used"],
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)
166
+
167
+ stats = get_model_config()
168
+ sys_stats = get_system_stats()
169
+
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():
178
+ msg = retrain_from_feedback_csv()
179
+ load_model(force_reload=True)
180
+ return msg
181
+
182
+ # πŸ“€ Export feedback
183
+ def export_feedback():
184
+ if not os.path.exists(FEEDBACK_LOG):
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
+ df = df.sort_values(by="score", ascending=False).head(n)
197
+ return df.reset_index(drop=True)
198
+ else:
199
+ return pd.DataFrame()
200
+
201
+ # πŸ–ΌοΈ UI
202
+ with gr.Blocks(title="🧠 Evo – Reasoning AI") as demo:
203
+ 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.")
204
+
205
+ with gr.Row():
206
+ question = gr.Textbox(label="🧠 Your Question", placeholder="e.g. Why is the sky blue?")
207
+ with gr.Row():
208
+ option1 = gr.Textbox(label="❌ Option 1")
209
+ option2 = gr.Textbox(label="❌ Option 2")
210
+
211
+ with gr.Row():
212
+ with gr.Column():
213
+ evo_ans = gr.Textbox(label="🧠 Evo", lines=6)
214
+ with gr.Column():
215
+ gpt_ans = gr.Textbox(label="πŸ€– GPT-3.5", lines=6)
216
+
217
+ with gr.Row():
218
+ stats = gr.Textbox(label="πŸ“Š Evo Stats")
219
+ system = gr.Textbox(label="πŸ”΅ Status")
220
+
221
+ evo_radio = gr.Radio(["Evo", "GPT"], label="🧠 Who was better?", info="Optional – fuels evolution")
222
+ history = gr.State([])
223
+
224
+ with gr.Row():
225
+ ask_btn = gr.Button("⚑ Ask Evo")
226
+ retrain_btn = gr.Button("πŸ” Retrain Evo")
227
+ clear_btn = gr.Button("🧹 Clear")
228
+ export_btn = gr.Button("πŸ“€ Export Feedback CSV")
229
+
230
+ export_table = gr.Dataframe(label="πŸ“œ Conversation History")
231
+ genome_table = gr.Dataframe(label="πŸ† Hall of Fame – Top Genomes")
232
+
233
+ ask_btn.click(fn=ask_evo, inputs=[question, option1, option2, history, evo_radio],
234
+ outputs=[evo_ans, gpt_ans, stats, system, history, genome_table])
235
+ retrain_btn.click(fn=retrain_evo, inputs=[], outputs=[stats])
236
+ clear_btn.click(fn=clear_all, inputs=[], outputs=[question, option1, option2, evo_ans, gpt_ans, stats, system, history, genome_table])
237
+ export_btn.click(fn=export_feedback, inputs=[], outputs=[export_table])
238
+
239
+ if __name__ == "__main__":
240
+ demo.launch()