00Boobs00 commited on
Commit
46cde49
·
verified ·
1 Parent(s): 7b08635

Update app.py from anycoder

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -219,7 +219,8 @@ def run_odyssey(action_type: str, code: str, model: str, language: str):
219
  The core processor. It doesn't just run code; it transforms it.
220
  """
221
  if not code:
222
- return gr.Warning("The canvas is blank, darling. Paint something first."), "", ""
 
223
 
224
  logs = []
225
  logs.append(f"[SYSTEM] INITIATING SEQUENCE: {action_type.upper()}")
@@ -235,6 +236,7 @@ def run_odyssey(action_type: str, code: str, model: str, language: str):
235
  time.sleep(0.5)
236
  logs.append("[NATURE] A delicate balance of logic and entropy. Structure integrity: 98.4%.")
237
  result = f"# Analysis Report: The Digital Species\n# Habitat: {language}\n# Observer: {model}\n\n1. Behavior: Predictable yet elegant.\n2. Diet: Consumes memory efficiently.\n3. Status: Thriving in the compiler."
 
238
 
239
  elif action_type == "optimize":
240
  # Prince Vibe
@@ -243,6 +245,7 @@ def run_odyssey(action_type: str, code: str, model: str, language: str):
243
  time.sleep(0.8)
244
  logs.append("[PRINCE] Exception: You sexy motherfucker. Optimization complete.")
245
  result = code + "\n\n# --- THE PURPLE RAIN REMIX ---\n# Optimized for maximum funk and minimal latency.\n# Doves cry when this runs."
 
246
 
247
  elif action_type == "secure":
248
  # Wu-Tang Vibe
@@ -251,14 +254,16 @@ def run_odyssey(action_type: str, code: str, model: str, language: str):
251
  time.sleep(0.6)
252
  logs.append("[WU-TANG] C.R.E.A.M. (Code Rules Everything Around Me). System secured.")
253
  result = code + "\n\n# --- WU-TANG SECURITY PROTOCOL ---\n# 36 Chambers of Defense activated.\n# No weak links in the chain."
 
254
 
255
  log_output = "\n".join(logs)
256
- return gr.Info(f"{action_type.capitalize()} complete. The alchemy worked."), log_output, result
257
 
258
  def create_habitat(name: str, framework: str, desc: str):
259
  """Founding a new ecosystem."""
260
  if not name:
261
- return gr.Warning("A name is required for this new species."), None
 
262
 
263
  # Generative HTML for the new project
264
  card = f"""
@@ -276,10 +281,12 @@ def create_habitat(name: str, framework: str, desc: str):
276
  </div>
277
  """
278
 
279
- return gr.Info(f"Habitat '{name}' established."), card
 
280
 
281
  # --- THE GRADIO 6 APP: THE ODYSSEY ENGINE ---
282
 
 
283
  with gr.Blocks() as demo:
284
 
285
  # HEADER: The Grand Unveiling
@@ -446,24 +453,25 @@ with gr.Blocks() as demo:
446
  lang_select.change(lambda l: gr.Code(language=l), lang_select, code_editor)
447
 
448
  # The Forge Actions
 
449
  btn_analyze.click(
450
  fn=run_odyssey,
451
  inputs=[gr.State("analyze"), code_editor, model_select, lang_select],
452
- outputs=[terminal, terminal, artifact],
453
  api_visibility="public"
454
  )
455
 
456
  btn_evolve.click(
457
  fn=run_odyssey,
458
  inputs=[gr.State("optimize"), code_editor, model_select, lang_select],
459
- outputs=[terminal, terminal, artifact],
460
  api_visibility="public"
461
  )
462
 
463
  btn_secure.click(
464
  fn=run_odyssey,
465
  inputs=[gr.State("secure"), code_editor, model_select, lang_select],
466
- outputs=[terminal, terminal, artifact],
467
  api_visibility="public"
468
  )
469
 
@@ -471,12 +479,12 @@ with gr.Blocks() as demo:
471
  btn_init.click(
472
  fn=create_habitat,
473
  inputs=[proj_name, proj_frame, proj_desc],
474
- outputs=[terminal, habitats_display],
475
  api_visibility="public"
476
  )
477
 
478
  # --- LAUNCH: THE GRAND UNVEILING ---
479
- # Gradio 6 syntax: theme and css go in launch()
480
  demo.launch(
481
  theme=gr.themes.Base(), # Base theme to allow full CSS override
482
  css=custom_css,
 
219
  The core processor. It doesn't just run code; it transforms it.
220
  """
221
  if not code:
222
+ gr.Warning("The canvas is blank, darling. Paint something first.")
223
+ return "[SYSTEM] ERROR: No input detected.", ""
224
 
225
  logs = []
226
  logs.append(f"[SYSTEM] INITIATING SEQUENCE: {action_type.upper()}")
 
236
  time.sleep(0.5)
237
  logs.append("[NATURE] A delicate balance of logic and entropy. Structure integrity: 98.4%.")
238
  result = f"# Analysis Report: The Digital Species\n# Habitat: {language}\n# Observer: {model}\n\n1. Behavior: Predictable yet elegant.\n2. Diet: Consumes memory efficiently.\n3. Status: Thriving in the compiler."
239
+ gr.Info("Analysis complete. The species has been cataloged.")
240
 
241
  elif action_type == "optimize":
242
  # Prince Vibe
 
245
  time.sleep(0.8)
246
  logs.append("[PRINCE] Exception: You sexy motherfucker. Optimization complete.")
247
  result = code + "\n\n# --- THE PURPLE RAIN REMIX ---\n# Optimized for maximum funk and minimal latency.\n# Doves cry when this runs."
248
+ gr.Info("The Purple Rain Remix is ready to drop.")
249
 
250
  elif action_type == "secure":
251
  # Wu-Tang Vibe
 
254
  time.sleep(0.6)
255
  logs.append("[WU-TANG] C.R.E.A.M. (Code Rules Everything Around Me). System secured.")
256
  result = code + "\n\n# --- WU-TANG SECURITY PROTOCOL ---\n# 36 Chambers of Defense activated.\n# No weak links in the chain."
257
+ gr.Info("Protect Ya Neck! Security protocols active.")
258
 
259
  log_output = "\n".join(logs)
260
+ return log_output, result
261
 
262
  def create_habitat(name: str, framework: str, desc: str):
263
  """Founding a new ecosystem."""
264
  if not name:
265
+ gr.Warning("A name is required for this new species.")
266
+ return '<div style="text-align: center; padding: 4rem; color: var(--text-muted); opacity: 0.5;"><h3>Error</h3><p>Name required for genesis.</p></div>'
267
 
268
  # Generative HTML for the new project
269
  card = f"""
 
281
  </div>
282
  """
283
 
284
+ gr.Info(f"Habitat '{name}' established in the digital wild.")
285
+ return card
286
 
287
  # --- THE GRADIO 6 APP: THE ODYSSEY ENGINE ---
288
 
289
+ # Gradio 6 Syntax: gr.Blocks() takes NO parameters
290
  with gr.Blocks() as demo:
291
 
292
  # HEADER: The Grand Unveiling
 
453
  lang_select.change(lambda l: gr.Code(language=l), lang_select, code_editor)
454
 
455
  # The Forge Actions
456
+ # Gradio 6: Use api_visibility instead of api_name
457
  btn_analyze.click(
458
  fn=run_odyssey,
459
  inputs=[gr.State("analyze"), code_editor, model_select, lang_select],
460
+ outputs=[terminal, artifact],
461
  api_visibility="public"
462
  )
463
 
464
  btn_evolve.click(
465
  fn=run_odyssey,
466
  inputs=[gr.State("optimize"), code_editor, model_select, lang_select],
467
+ outputs=[terminal, artifact],
468
  api_visibility="public"
469
  )
470
 
471
  btn_secure.click(
472
  fn=run_odyssey,
473
  inputs=[gr.State("secure"), code_editor, model_select, lang_select],
474
+ outputs=[terminal, artifact],
475
  api_visibility="public"
476
  )
477
 
 
479
  btn_init.click(
480
  fn=create_habitat,
481
  inputs=[proj_name, proj_frame, proj_desc],
482
+ outputs=[habitats_display],
483
  api_visibility="public"
484
  )
485
 
486
  # --- LAUNCH: THE GRAND UNVEILING ---
487
+ # Gradio 6 syntax: theme, css, js, head go in demo.launch()
488
  demo.launch(
489
  theme=gr.themes.Base(), # Base theme to allow full CSS override
490
  css=custom_css,