Update app.py
Browse files
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 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
}
|
| 89 |
-
target_model = openrouter_model_map.get(model_choice, "
|
| 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=
|
| 204 |
-
value=
|
| 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
|
| 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()
|