Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +60 -0
Gradio_UI.py
CHANGED
|
@@ -259,6 +259,28 @@ class GradioUI:
|
|
| 259 |
),
|
| 260 |
"",
|
| 261 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
def launch(self, **kwargs):
|
| 264 |
import gradio as gr
|
|
@@ -266,6 +288,44 @@ class GradioUI:
|
|
| 266 |
with gr.Blocks(fill_height=True) as demo:
|
| 267 |
stored_messages = gr.State([])
|
| 268 |
file_uploads_log = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
chatbot = gr.Chatbot(
|
| 270 |
label="Agent",
|
| 271 |
type="messages",
|
|
|
|
| 259 |
),
|
| 260 |
"",
|
| 261 |
)
|
| 262 |
+
|
| 263 |
+
def update_model(self, model_id):
|
| 264 |
+
"""Update the agent's model with a new model ID"""
|
| 265 |
+
import gradio as gr
|
| 266 |
+
|
| 267 |
+
try:
|
| 268 |
+
from smolagents import HfApiModel
|
| 269 |
+
|
| 270 |
+
# Create a new model with the provided ID
|
| 271 |
+
new_model = HfApiModel(
|
| 272 |
+
max_tokens=2096,
|
| 273 |
+
temperature=0.5,
|
| 274 |
+
model_id=model_id,
|
| 275 |
+
custom_role_conversions=None,
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
# Update the agent's model
|
| 279 |
+
self.agent.model = new_model
|
| 280 |
+
|
| 281 |
+
return gr.Textbox(f"Model updated to: {model_id}", visible=True)
|
| 282 |
+
except Exception as e:
|
| 283 |
+
return gr.Textbox(f"Error updating model: {str(e)}", visible=True)
|
| 284 |
|
| 285 |
def launch(self, **kwargs):
|
| 286 |
import gradio as gr
|
|
|
|
| 288 |
with gr.Blocks(fill_height=True) as demo:
|
| 289 |
stored_messages = gr.State([])
|
| 290 |
file_uploads_log = gr.State([])
|
| 291 |
+
|
| 292 |
+
# Add model selection UI elements
|
| 293 |
+
with gr.Row():
|
| 294 |
+
with gr.Column(scale=3):
|
| 295 |
+
model_input = gr.Textbox(
|
| 296 |
+
label="Enter Model ID",
|
| 297 |
+
placeholder="e.g., Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 298 |
+
value="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 299 |
+
)
|
| 300 |
+
with gr.Column(scale=1):
|
| 301 |
+
update_button = gr.Button("Update Model")
|
| 302 |
+
|
| 303 |
+
model_status = gr.Textbox(label="Model Status", interactive=False, visible=False)
|
| 304 |
+
|
| 305 |
+
update_button.click(
|
| 306 |
+
self.update_model,
|
| 307 |
+
[model_input],
|
| 308 |
+
[model_status],
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
# Dropdown with preset model options
|
| 312 |
+
model_dropdown = gr.Dropdown(
|
| 313 |
+
choices=[
|
| 314 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 315 |
+
"https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
| 316 |
+
"CohereLabs/c4ai-command-a-03-2025"
|
| 317 |
+
],
|
| 318 |
+
label="Preset Models",
|
| 319 |
+
value="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
# Update the textbox when a preset is selected
|
| 323 |
+
model_dropdown.change(
|
| 324 |
+
lambda x: x,
|
| 325 |
+
[model_dropdown],
|
| 326 |
+
[model_input]
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
chatbot = gr.Chatbot(
|
| 330 |
label="Agent",
|
| 331 |
type="messages",
|