Aigenthix commited on
Commit
d640b80
·
verified ·
1 Parent(s): 48a01db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -9
app.py CHANGED
@@ -55,6 +55,27 @@ def init_db():
55
 
56
  init_db()
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  # --- Common LLM API Request Orchestrator ---
59
  def call_llm(provider, api_key, model_choice, system_prompt, user_message, chat_history_format=None):
60
  messages = [{"role": "system", "content": system_prompt}]
@@ -80,15 +101,16 @@ def call_llm(provider, api_key, model_choice, system_prompt, user_message, chat_
80
 
81
  elif provider == "OpenRouter":
82
  headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
 
 
83
  openrouter_model_map = {
84
- "llama-3.1-8b-instant": "meta-llama/llama-3.1-8b-instruct",
85
- "llama-3.1-70b-versatile": "meta-llama/llama-3.1-70b-instruct",
86
- "openai/gpt-oss-20b": "openai/gpt-3.5-turbo",
87
- "whisper-large-v3-turbo": "meta-llama/llama-3.1-8b-instruct"
88
  }
89
- target_model = openrouter_model_map.get(model_choice, "meta-llama/llama-3.1-8b-instruct")
90
 
91
- # FIXED: Corrected structural syntax for payload dictionary assignment
92
  payload = {
93
  "model": target_model,
94
  "messages": messages,
@@ -199,11 +221,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
199
  gr.Markdown("### 🔑 Global Control Tower")
200
  provider_select = gr.Dropdown(choices=["Groq", "OpenRouter"], value="Groq", label="API Gateway Provider")
201
  token_input = gr.Textbox(label="User API Secret Key", type="password", placeholder="gsk_... or sk-or-...")
 
 
202
  model_select = gr.Dropdown(
203
- choices=["llama-3.1-8b-instant", "llama-3.1-70b-versatile", "openai/gpt-oss-20b", "whisper-large-v3-turbo"],
204
- value="llama-3.1-8b-instant",
205
  label="Target Engine Architecture"
206
  )
 
207
  gr.Markdown("✨ **Global Platform Database State Schema:**\n- `phase` (Discovery, Data Prep, Modeling, Validation)\n- `task_name` (Structural workflow description string)\n- `owner` (Assigned personnel scientist name)\n- `timeline` (Expected operational delivery time frames)\n- `priority` (High, Medium, Low)")
208
 
209
  with gr.Column(scale=2):
@@ -214,7 +239,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
214
  gr.Markdown("Chat with this engine normally, or tell it to log a brand-new task assignment milestone directly into the active SQLite infrastructure.")
215
 
216
  chatbot_viewport = gr.Chatbot(type="messages", label="Operational History Workspace")
217
- chat_input = gr.Textbox(placeholder="Say hello, or submit task details to log (e.g., Log a task in Validation phase named Run final audit owned by M. Reddy for Week 8 with High priority)", label="Your Message")
218
  send_btn = gr.Button("Submit Message", variant="primary")
219
 
220
  send_btn.click(
@@ -242,5 +267,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
242
  outputs=[output_data_table, sql_status_display]
243
  )
244
 
 
 
 
 
 
 
 
 
245
  if __name__ == "__main__":
246
  demo.launch()
 
55
 
56
  init_db()
57
 
58
+ # --- Dynamic Model Dropdown Refresher Logic ---
59
+ GROQ_MODELS = [
60
+ "llama-3.1-8b-instant",
61
+ "llama-3.1-70b-versatile",
62
+ "openai/gpt-oss-20b",
63
+ "whisper-large-v3-turbo"
64
+ ]
65
+
66
+ OPENROUTER_MODELS = [
67
+ "nvidia/nemotron-3.5-content-safety:free",
68
+ "qwen/qwen3.7-plus",
69
+ "microsoft/mai-transcribe-1.5",
70
+ "google/gemini-embedding-2"
71
+ ]
72
+
73
+ def update_model_dropdown(provider):
74
+ if provider == "Groq":
75
+ return gr.Dropdown(choices=GROQ_MODELS, value=GROQ_MODELS[0], label="Target Engine Architecture")
76
+ elif provider == "OpenRouter":
77
+ return gr.Dropdown(choices=OPENROUTER_MODELS, value=OPENROUTER_MODELS[0], label="Target Engine Architecture")
78
+
79
  # --- Common LLM API Request Orchestrator ---
80
  def call_llm(provider, api_key, model_choice, system_prompt, user_message, chat_history_format=None):
81
  messages = [{"role": "system", "content": system_prompt}]
 
101
 
102
  elif provider == "OpenRouter":
103
  headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
104
+
105
+ # Maps user-facing selection directly to their OpenRouter global endpoints
106
  openrouter_model_map = {
107
+ "nvidia/nemotron-3.5-content-safety:free": "nvidia/nemotron-3.5-content-safety:free",
108
+ "qwen/qwen3.7-plus": "qwen/qwen3.7-plus",
109
+ "microsoft/mai-transcribe-1.5": "microsoft/mai-transcribe-1.5",
110
+ "google/gemini-embedding-2": "google/gemini-embedding-2"
111
  }
112
+ target_model = openrouter_model_map.get(model_choice, "nvidia/nemotron-3.5-content-safety:free")
113
 
 
114
  payload = {
115
  "model": target_model,
116
  "messages": messages,
 
221
  gr.Markdown("### 🔑 Global Control Tower")
222
  provider_select = gr.Dropdown(choices=["Groq", "OpenRouter"], value="Groq", label="API Gateway Provider")
223
  token_input = gr.Textbox(label="User API Secret Key", type="password", placeholder="gsk_... or sk-or-...")
224
+
225
+ # This component gets updated dynamically by the event handler below
226
  model_select = gr.Dropdown(
227
+ choices=GROQ_MODELS,
228
+ value=GROQ_MODELS[0],
229
  label="Target Engine Architecture"
230
  )
231
+
232
  gr.Markdown("✨ **Global Platform Database State Schema:**\n- `phase` (Discovery, Data Prep, Modeling, Validation)\n- `task_name` (Structural workflow description string)\n- `owner` (Assigned personnel scientist name)\n- `timeline` (Expected operational delivery time frames)\n- `priority` (High, Medium, Low)")
233
 
234
  with gr.Column(scale=2):
 
239
  gr.Markdown("Chat with this engine normally, or tell it to log a brand-new task assignment milestone directly into the active SQLite infrastructure.")
240
 
241
  chatbot_viewport = gr.Chatbot(type="messages", label="Operational History Workspace")
242
+ chat_input = gr.Textbox(placeholder="Say hello, or submit task details to log...", label="Your Message")
243
  send_btn = gr.Button("Submit Message", variant="primary")
244
 
245
  send_btn.click(
 
267
  outputs=[output_data_table, sql_status_display]
268
  )
269
 
270
+ # --- REACTIVE EVENT LISTENER ---
271
+ # Whenever the provider dropdown changes, change the choices of the model select dropdown
272
+ provider_select.change(
273
+ fn=update_model_dropdown,
274
+ inputs=[provider_select],
275
+ outputs=[model_select]
276
+ )
277
+
278
  if __name__ == "__main__":
279
  demo.launch()