AIencoder commited on
Commit
91d24fc
·
verified ·
1 Parent(s): 5a61b94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +244 -33
app.py CHANGED
@@ -33,10 +33,10 @@ def get_status():
33
  r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=2)
34
  if r.status_code == 200:
35
  models = r.json().get("models", [])
36
- return f" Online | {len(models)} models loaded"
37
  except:
38
  pass
39
- return " Starting..."
40
 
41
  def transcribe_audio(audio):
42
  if audio is None:
@@ -193,71 +193,282 @@ def review_code(code, model_name, max_tokens):
193
  return f"❌ Error: {e}"
194
 
195
  css = """
196
- .container { max-width: 1200px; margin: auto; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  footer { display: none !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  """
199
 
200
  with gr.Blocks(title="Axon v6", css=css, theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue")) as demo:
201
 
202
- gr.Markdown("# 🔥 Axon v6\n### AI Coding Assistant • 10 Models • 100% Local • No Rate Limits")
203
-
204
- status = gr.Markdown(value=get_status, every=5)
 
 
 
 
205
 
 
206
  with gr.Row():
207
- model_dropdown = gr.Dropdown(choices=list(MODELS.keys()), value="Qwen2.5 Coder 3B", label="🤖 Model", scale=3)
 
 
 
 
 
 
 
 
 
 
208
  temperature = gr.Slider(0, 1, value=0.7, step=0.1, label="🌡️ Creativity", scale=2)
209
  max_tokens = gr.Slider(256, 8192, value=2048, step=256, label="📏 Max Length", scale=2)
210
 
211
- with gr.Tabs():
212
 
 
213
  with gr.TabItem("💬 Chat"):
214
- chatbot = gr.Chatbot(height=450, show_copy_button=True)
 
 
 
 
 
 
215
  with gr.Row():
216
- msg = gr.Textbox(placeholder="Ask a coding question...", show_label=False, scale=8, lines=2)
217
- send = gr.Button("Send", variant="primary", scale=1)
 
 
 
 
 
 
 
 
218
  with gr.Row():
219
- audio_input = gr.Audio(sources=["microphone"], type="filepath", label="🎤 Voice")
220
- transcribe_btn = gr.Button("🎤 Transcribe")
221
- clear = gr.Button("🗑️ Clear")
222
- with gr.Accordion("💡 Examples", open=False):
223
- gr.Examples(["Write a Python quicksort function", "Explain async/await in JavaScript"], inputs=msg)
 
 
 
 
 
 
224
 
 
225
  with gr.TabItem("⚡ Generate"):
226
  with gr.Row():
227
  with gr.Column(scale=1):
228
- gen_prompt = gr.Textbox(label="📝 Describe what you want", lines=4)
229
- gen_lang = gr.Dropdown(LANGUAGES, value="Python", label="🔤 Language")
230
- gen_temp = gr.Slider(0, 1, value=0.3, step=0.1, label="🌡️ Creativity")
231
- gen_btn = gr.Button("⚡ Generate", variant="primary", size="lg")
 
 
 
 
 
 
 
232
  with gr.Column(scale=2):
233
- gen_output = gr.Code(label="Generated Code", language="python", lines=20)
234
 
 
235
  with gr.TabItem("🔍 Explain"):
236
  with gr.Row():
237
  with gr.Column(scale=1):
238
- explain_input = gr.Code(label="📋 Paste code", lines=12)
239
- explain_detail = gr.Radio(["Brief", "Normal", "Detailed"], value="Normal", label="📊 Detail")
240
- explain_btn = gr.Button("🔍 Explain", variant="primary", size="lg")
 
 
 
 
 
 
241
  with gr.Column(scale=1):
242
- explain_output = gr.Markdown(label="Explanation")
243
 
244
- with gr.TabItem("🔧 Fix"):
 
245
  with gr.Row():
246
  with gr.Column(scale=1):
247
- fix_input = gr.Code(label="🐛 Buggy code", lines=10)
248
- fix_error = gr.Textbox(label="❌ Error message", lines=3)
249
- fix_btn = gr.Button("🔧 Fix", variant="primary", size="lg")
 
 
 
 
 
 
250
  with gr.Column(scale=1):
251
- fix_output = gr.Markdown(label="Fixed Code")
252
 
 
253
  with gr.TabItem("📋 Review"):
254
  with gr.Row():
255
  with gr.Column(scale=1):
256
- review_input = gr.Code(label="📋 Code to review", lines=15)
257
- review_btn = gr.Button("📋 Review", variant="primary", size="lg")
 
258
  with gr.Column(scale=1):
259
- review_output = gr.Markdown(label="Review")
 
 
 
 
 
 
 
260
 
 
261
  def respond(message, history, model, temp, tokens):
262
  history = history or []
263
  for updated_history in chat_stream(message, history, model, temp, tokens):
 
33
  r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=2)
34
  if r.status_code == 200:
35
  models = r.json().get("models", [])
36
+ return f"🟢 Online {len(models)} models"
37
  except:
38
  pass
39
+ return "🟡 Starting..."
40
 
41
  def transcribe_audio(audio):
42
  if audio is None:
 
193
  return f"❌ Error: {e}"
194
 
195
  css = """
196
+ /* Global */
197
+ .gradio-container {
198
+ max-width: 1400px !important;
199
+ margin: auto !important;
200
+ font-family: 'Inter', system-ui, sans-serif !important;
201
+ }
202
+
203
+ /* Header */
204
+ .header-container {
205
+ text-align: center;
206
+ padding: 20px 0;
207
+ margin-bottom: 10px;
208
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
209
+ border-radius: 16px;
210
+ color: white;
211
+ }
212
+ .header-container h1 {
213
+ margin: 0;
214
+ font-size: 2.5rem;
215
+ font-weight: 700;
216
+ }
217
+ .header-container p {
218
+ margin: 8px 0 0 0;
219
+ opacity: 0.9;
220
+ font-size: 1.1rem;
221
+ }
222
+
223
+ /* Status badge */
224
+ .status-badge {
225
+ display: inline-block;
226
+ padding: 6px 16px;
227
+ border-radius: 20px;
228
+ font-size: 0.9rem;
229
+ font-weight: 500;
230
+ background: rgba(255,255,255,0.15);
231
+ backdrop-filter: blur(10px);
232
+ }
233
+
234
+ /* Settings bar */
235
+ .settings-row {
236
+ background: #f8f9fc;
237
+ padding: 16px 20px;
238
+ border-radius: 12px;
239
+ margin-bottom: 16px;
240
+ border: 1px solid #e5e7eb;
241
+ }
242
+
243
+ /* Tabs */
244
+ .tabs {
245
+ border-radius: 12px !important;
246
+ overflow: hidden;
247
+ }
248
+ .tab-nav {
249
+ background: #f8f9fc !important;
250
+ padding: 8px !important;
251
+ gap: 8px !important;
252
+ }
253
+ .tab-nav button {
254
+ border-radius: 8px !important;
255
+ font-weight: 500 !important;
256
+ padding: 12px 20px !important;
257
+ transition: all 0.2s ease !important;
258
+ }
259
+ .tab-nav button.selected {
260
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
261
+ color: white !important;
262
+ }
263
+
264
+ /* Chat */
265
+ .chatbot {
266
+ border-radius: 12px !important;
267
+ border: 1px solid #e5e7eb !important;
268
+ }
269
+ .chatbot .message {
270
+ border-radius: 12px !important;
271
+ padding: 12px 16px !important;
272
+ }
273
+
274
+ /* Buttons */
275
+ .primary-btn {
276
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
277
+ border: none !important;
278
+ border-radius: 10px !important;
279
+ font-weight: 600 !important;
280
+ padding: 12px 24px !important;
281
+ transition: transform 0.2s ease, box-shadow 0.2s ease !important;
282
+ }
283
+ .primary-btn:hover {
284
+ transform: translateY(-2px) !important;
285
+ box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4) !important;
286
+ }
287
+
288
+ /* Code blocks */
289
+ .code-block {
290
+ border-radius: 12px !important;
291
+ border: 1px solid #e5e7eb !important;
292
+ overflow: hidden;
293
+ }
294
+
295
+ /* Cards */
296
+ .card {
297
+ background: white;
298
+ border-radius: 16px;
299
+ padding: 20px;
300
+ border: 1px solid #e5e7eb;
301
+ box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
302
+ }
303
+
304
+ /* Inputs */
305
+ .input-box textarea, .input-box input {
306
+ border-radius: 10px !important;
307
+ border: 1px solid #e5e7eb !important;
308
+ padding: 12px 16px !important;
309
+ transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
310
+ }
311
+ .input-box textarea:focus, .input-box input:focus {
312
+ border-color: #667eea !important;
313
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15) !important;
314
+ }
315
+
316
+ /* Hide footer */
317
  footer { display: none !important; }
318
+
319
+ /* Feature cards */
320
+ .feature-grid {
321
+ display: grid;
322
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
323
+ gap: 12px;
324
+ margin-top: 16px;
325
+ }
326
+ .feature-card {
327
+ background: linear-gradient(135deg, #f8f9fc 0%, #f1f3f8 100%);
328
+ padding: 16px;
329
+ border-radius: 12px;
330
+ text-align: center;
331
+ border: 1px solid #e5e7eb;
332
+ }
333
+ .feature-card .icon {
334
+ font-size: 1.5rem;
335
+ margin-bottom: 8px;
336
+ }
337
+ .feature-card .title {
338
+ font-weight: 600;
339
+ font-size: 0.95rem;
340
+ }
341
  """
342
 
343
  with gr.Blocks(title="Axon v6", css=css, theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue")) as demo:
344
 
345
+ # Header
346
+ gr.HTML("""
347
+ <div class="header-container">
348
+ <h1>🔥 Axon v6</h1>
349
+ <p>AI Coding Assistant • 10 Models • 100% Local • No Rate Limits</p>
350
+ </div>
351
+ """)
352
 
353
+ # Status
354
  with gr.Row():
355
+ status = gr.Markdown(value=get_status, every=5)
356
+
357
+ # Settings
358
+ with gr.Row(elem_classes="settings-row"):
359
+ model_dropdown = gr.Dropdown(
360
+ choices=list(MODELS.keys()),
361
+ value="Qwen2.5 Coder 3B",
362
+ label="🤖 Model",
363
+ scale=3,
364
+ container=False
365
+ )
366
  temperature = gr.Slider(0, 1, value=0.7, step=0.1, label="🌡️ Creativity", scale=2)
367
  max_tokens = gr.Slider(256, 8192, value=2048, step=256, label="📏 Max Length", scale=2)
368
 
369
+ with gr.Tabs(elem_classes="tabs"):
370
 
371
+ # Chat Tab
372
  with gr.TabItem("💬 Chat"):
373
+ chatbot = gr.Chatbot(
374
+ height=480,
375
+ show_copy_button=True,
376
+ bubble_full_width=False,
377
+ avatar_images=(None, "https://api.dicebear.com/7.x/bottts/svg?seed=axon")
378
+ )
379
+
380
  with gr.Row():
381
+ msg = gr.Textbox(
382
+ placeholder="Ask anything about coding... (Enter to send)",
383
+ show_label=False,
384
+ scale=8,
385
+ lines=1,
386
+ container=False,
387
+ elem_classes="input-box"
388
+ )
389
+ send = gr.Button("Send ➤", variant="primary", scale=1, elem_classes="primary-btn")
390
+
391
  with gr.Row():
392
+ audio_input = gr.Audio(sources=["microphone"], type="filepath", label="🎤 Voice", scale=2)
393
+ transcribe_btn = gr.Button("🎤 Transcribe", scale=1)
394
+ clear = gr.Button("🗑️ Clear", scale=1)
395
+
396
+ with gr.Accordion("💡 Quick Prompts", open=False):
397
+ gr.Examples([
398
+ "Write a Python function to find all prime numbers up to n",
399
+ "Explain async/await vs promises in JavaScript",
400
+ "Create a REST API endpoint with authentication",
401
+ "How do I implement a binary search tree?",
402
+ ], inputs=msg)
403
 
404
+ # Generate Tab
405
  with gr.TabItem("⚡ Generate"):
406
  with gr.Row():
407
  with gr.Column(scale=1):
408
+ gen_prompt = gr.Textbox(
409
+ label="📝 What do you want to build?",
410
+ placeholder="e.g., A function that validates email addresses with regex",
411
+ lines=5,
412
+ elem_classes="input-box"
413
+ )
414
+ with gr.Row():
415
+ gen_lang = gr.Dropdown(LANGUAGES, value="Python", label="🔤 Language", scale=2)
416
+ gen_temp = gr.Slider(0, 1, value=0.3, step=0.1, label="🌡️", scale=1)
417
+ gen_btn = gr.Button("⚡ Generate Code", variant="primary", size="lg", elem_classes="primary-btn")
418
+
419
  with gr.Column(scale=2):
420
+ gen_output = gr.Code(label="Generated Code", language="python", lines=22, elem_classes="code-block")
421
 
422
+ # Explain Tab
423
  with gr.TabItem("🔍 Explain"):
424
  with gr.Row():
425
  with gr.Column(scale=1):
426
+ explain_input = gr.Code(label="📋 Paste your code", lines=14, elem_classes="code-block")
427
+ explain_detail = gr.Radio(
428
+ ["Brief", "Normal", "Detailed"],
429
+ value="Normal",
430
+ label="📊 Explanation Detail",
431
+ info="Brief = 2-3 sentences, Detailed = full breakdown"
432
+ )
433
+ explain_btn = gr.Button("🔍 Explain Code", variant="primary", size="lg", elem_classes="primary-btn")
434
+
435
  with gr.Column(scale=1):
436
+ explain_output = gr.Markdown(label="Explanation", elem_classes="card")
437
 
438
+ # Fix Tab
439
+ with gr.TabItem("🔧 Debug"):
440
  with gr.Row():
441
  with gr.Column(scale=1):
442
+ fix_input = gr.Code(label="🐛 Paste buggy code", lines=12, elem_classes="code-block")
443
+ fix_error = gr.Textbox(
444
+ label=" Error message (optional)",
445
+ placeholder="Paste error or describe the issue",
446
+ lines=3,
447
+ elem_classes="input-box"
448
+ )
449
+ fix_btn = gr.Button("🔧 Fix Code", variant="primary", size="lg", elem_classes="primary-btn")
450
+
451
  with gr.Column(scale=1):
452
+ fix_output = gr.Markdown(label="Solution", elem_classes="card")
453
 
454
+ # Review Tab
455
  with gr.TabItem("📋 Review"):
456
  with gr.Row():
457
  with gr.Column(scale=1):
458
+ review_input = gr.Code(label="📋 Code to review", lines=16, elem_classes="code-block")
459
+ review_btn = gr.Button("📋 Review Code", variant="primary", size="lg", elem_classes="primary-btn")
460
+
461
  with gr.Column(scale=1):
462
+ review_output = gr.Markdown(label="Code Review", elem_classes="card")
463
+
464
+ # Footer info
465
+ gr.HTML("""
466
+ <div style="text-align: center; padding: 20px; opacity: 0.7; font-size: 0.85rem;">
467
+ <p>Running 100% locally via Ollama • Models cached after first load • No data sent externally</p>
468
+ </div>
469
+ """)
470
 
471
+ # Event handlers
472
  def respond(message, history, model, temp, tokens):
473
  history = history or []
474
  for updated_history in chat_stream(message, history, model, temp, tokens):