WhoDat55 commited on
Commit
70bc965
·
verified ·
1 Parent(s): f02beae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -74
app.py CHANGED
@@ -8,25 +8,11 @@ from typing import List, Dict, Any
8
 
9
  MCP_SERVER_URL = "https://mcp-1st-birthday-project-conductor-core-mcp.hf.space/execute"
10
 
11
- # --- HARDCODED DEFAULTS (The Safety Net) ---
12
- # These populate the dropdowns if config.ini is missing or empty.
13
- DEFAULT_PROVIDER_MODELS = {
14
- "Google Gemini": [
15
- "gemini-2.0-flash-lite",
16
- "gemini-1.5-pro-latest",
17
- "gemini-1.5-flash-latest",
18
- "gemini-1.0-pro"
19
- ],
20
- "Anthropic": [
21
- "claude-3-opus-20240229",
22
- "claude-3-sonnet-20240229",
23
- "claude-3-haiku-20240307"
24
- ],
25
- "OpenAI": [
26
- "gpt-4-turbo",
27
- "gpt-4o",
28
- "gpt-3.5-turbo"
29
- ],
30
  "Custom": []
31
  }
32
 
@@ -45,41 +31,40 @@ def classify_model_by_provider(model_label: str) -> str:
45
 
46
  def load_client_config():
47
  config = {}
 
 
48
 
49
- # 1. Start with the Hardcoded Defaults
50
- # We use deep copy logic to ensure we don't mess up the original global dict
51
- coder_by_provider = {k: v[:] for k, v in DEFAULT_PROVIDER_MODELS.items()}
52
- strategist_by_provider = {k: v[:] for k, v in DEFAULT_PROVIDER_MODELS.items()}
53
-
54
- # 2. Try to load from config.ini to ADD extra models
55
  if os.path.exists('config.ini'):
56
  parser = ConfigParser()
57
  parser.read('config.ini')
58
  try:
59
  if 'CODER_MODELS' in parser:
60
- for label, _ in parser['CODER_MODELS'].items():
61
- provider = classify_model_by_provider(label)
62
- # Only add if not already in the list to avoid duplicates
63
- if label not in coder_by_provider[provider]:
64
- coder_by_provider[provider].append(label)
65
-
66
  if 'STRATEGIST_MODELS' in parser:
67
- for label, _ in parser['STRATEGIST_MODELS'].items():
68
- provider = classify_model_by_provider(label)
69
- if label not in strategist_by_provider[provider]:
70
- strategist_by_provider[provider].append(label)
71
  except Exception as e:
72
  print(f"Config parsing warning: {e}")
73
 
74
- config['coder_by_provider'] = coder_by_provider
75
- config['strategist_by_provider'] = strategist_by_provider
 
 
 
 
 
76
 
77
- # Flatten lists for easy searching later
78
- config['coder_models'] = [m for models in coder_by_provider.values() for m in models]
79
- config['strategist_models'] = [m for models in strategist_by_provider.values() for m in models]
80
 
81
- config['coder_default'] = os.getenv('CODER_MODEL_DEFAULT_LABEL', 'gemini-2.0-flash-lite')
82
- config['strategist_default'] = os.getenv('STRATEGIST_MODEL_DEFAULT_LABEL', 'gemini-2.0-flash-lite')
 
 
 
 
83
 
84
  return config
85
 
@@ -296,36 +281,11 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
296
  if strategist_default:
297
  initial_strategist_provider = classify_model_by_provider(strategist_default)
298
 
299
- # TASK 1: Set Default Models on Launch
300
- # We override the config default if specific models are requested
301
- default_model_label = "gemini-2.0-flash-lite"
302
-
303
- # Helper to safely get a default value
304
- def get_safe_default(provider, preferred_label):
305
- models = CLIENT_CONFIG['coder_by_provider'].get(provider, [])
306
- if preferred_label in models:
307
- return preferred_label
308
- return models[0] if models else None
309
-
310
- initial_coder_model_val = get_safe_default(initial_coder_provider, default_model_label)
311
- initial_strategist_model_val = get_safe_default(initial_strategist_provider, default_model_label)
312
-
313
  def load_demo_data():
314
  # TASK 2: "Load Demo" Button Model Switch
315
  # Switch to a high-end model for the demo
316
  demo_model_label = "gemini-2.5-pro"
317
- # Fallback if exact label not found, try to find a 'pro' model
318
- models = CLIENT_CONFIG['coder_by_provider'].get("Google Gemini", [])
319
- target_model = demo_model_label
320
- if demo_model_label not in models:
321
- # Try to find a pro model
322
- pro_models = [m for m in models if 'pro' in m.lower()]
323
- if pro_models:
324
- target_model = pro_models[0]
325
- elif models:
326
- target_model = models[0]
327
-
328
- return DEMO_BLUEPRINT, DEMO_INTENT, gr.update(value=target_model)
329
 
330
  def start_execution_sequence():
331
  return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
@@ -356,8 +316,8 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
356
  coder_models_for_reset = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
357
  strategist_models_for_reset = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
358
 
359
- coder_reset_value = initial_coder_model_val
360
- strategist_reset_value = initial_strategist_model_val
361
 
362
  return (
363
  "", # blueprint_input
@@ -383,14 +343,14 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
383
  with gr.Column():
384
  gr.Markdown("### Coder Agent")
385
  coder_provider = gr.Dropdown(
386
- choices=list(DEFAULT_PROVIDER_MODELS.keys()),
387
  value=initial_coder_provider,
388
  label="Provider",
389
  interactive=True
390
  )
391
  coder_model = gr.Dropdown(
392
  choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
393
- value=initial_coder_model_val,
394
  label="Model",
395
  interactive=True
396
  )
@@ -432,14 +392,14 @@ Produce a pro level styled and tuned them GUI that has 1 button that when presse
432
  with gr.Column():
433
  gr.Markdown("### Strategist Agent")
434
  strategist_provider = gr.Dropdown(
435
- choices=list(DEFAULT_PROVIDER_MODELS.keys()),
436
  value=initial_strategist_provider,
437
  label="Provider",
438
  interactive=True
439
  )
440
  strategist_model = gr.Dropdown(
441
  choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
442
- value=initial_strategist_model_val,
443
  label="Model",
444
  interactive=True
445
  )
 
8
 
9
  MCP_SERVER_URL = "https://mcp-1st-birthday-project-conductor-core-mcp.hf.space/execute"
10
 
11
+ # HARDCODED PROVIDER MAPPING (Directive 1.1, 1.2, 1.3)
12
+ PROVIDER_MODEL_MAPPING = {
13
+ "Google Gemini": [],
14
+ "Anthropic": [],
15
+ "OpenAI": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  "Custom": []
17
  }
18
 
 
31
 
32
  def load_client_config():
33
  config = {}
34
+ coder_models = {}
35
+ strategist_models = {}
36
 
 
 
 
 
 
 
37
  if os.path.exists('config.ini'):
38
  parser = ConfigParser()
39
  parser.read('config.ini')
40
  try:
41
  if 'CODER_MODELS' in parser:
42
+ for label, entry in parser['CODER_MODELS'].items():
43
+ coder_models[label] = label
 
 
 
 
44
  if 'STRATEGIST_MODELS' in parser:
45
+ for label, entry in parser['STRATEGIST_MODELS'].items():
46
+ strategist_models[label] = label
 
 
47
  except Exception as e:
48
  print(f"Config parsing warning: {e}")
49
 
50
+ # Build provider-grouped structure
51
+ coder_by_provider = {p: [] for p in PROVIDER_MODEL_MAPPING.keys()}
52
+ strategist_by_provider = {p: [] for p in PROVIDER_MODEL_MAPPING.keys()}
53
+
54
+ for label in coder_models.keys():
55
+ provider = classify_model_by_provider(label)
56
+ coder_by_provider[provider].append(label)
57
 
58
+ for label in strategist_models.keys():
59
+ provider = classify_model_by_provider(label)
60
+ strategist_by_provider[provider].append(label)
61
 
62
+ config['coder_by_provider'] = coder_by_provider
63
+ config['strategist_by_provider'] = strategist_by_provider
64
+ config['coder_models'] = list(coder_models.keys())
65
+ config['strategist_models'] = list(strategist_models.keys())
66
+ config['coder_default'] = os.getenv('CODER_MODEL_DEFAULT_LABEL', '')
67
+ config['strategist_default'] = os.getenv('STRATEGIST_MODEL_DEFAULT_LABEL', '')
68
 
69
  return config
70
 
 
281
  if strategist_default:
282
  initial_strategist_provider = classify_model_by_provider(strategist_default)
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def load_demo_data():
285
  # TASK 2: "Load Demo" Button Model Switch
286
  # Switch to a high-end model for the demo
287
  demo_model_label = "gemini-2.5-pro"
288
+ return DEMO_BLUEPRINT, DEMO_INTENT, gr.update(value=demo_model_label)
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  def start_execution_sequence():
291
  return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
 
316
  coder_models_for_reset = CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, [])
317
  strategist_models_for_reset = CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, [])
318
 
319
+ coder_reset_value = coder_models_for_reset[0] if coder_models_for_reset else None
320
+ strategist_reset_value = strategist_models_for_reset[0] if strategist_models_for_reset else None
321
 
322
  return (
323
  "", # blueprint_input
 
343
  with gr.Column():
344
  gr.Markdown("### Coder Agent")
345
  coder_provider = gr.Dropdown(
346
+ choices=list(PROVIDER_MODEL_MAPPING.keys()),
347
  value=initial_coder_provider,
348
  label="Provider",
349
  interactive=True
350
  )
351
  coder_model = gr.Dropdown(
352
  choices=CLIENT_CONFIG['coder_by_provider'].get(initial_coder_provider, []),
353
+ value=coder_default if coder_default else None,
354
  label="Model",
355
  interactive=True
356
  )
 
392
  with gr.Column():
393
  gr.Markdown("### Strategist Agent")
394
  strategist_provider = gr.Dropdown(
395
+ choices=list(PROVIDER_MODEL_MAPPING.keys()),
396
  value=initial_strategist_provider,
397
  label="Provider",
398
  interactive=True
399
  )
400
  strategist_model = gr.Dropdown(
401
  choices=CLIENT_CONFIG['strategist_by_provider'].get(initial_strategist_provider, []),
402
+ value=strategist_default if strategist_default else None,
403
  label="Model",
404
  interactive=True
405
  )