Spaces:
Runtime error
Runtime error
Update Gradio app with multiple files
Browse files- app.py +40 -15
- requirements.txt +10 -13
app.py
CHANGED
|
@@ -114,10 +114,15 @@ def create_interface():
|
|
| 114 |
for i, step in enumerate(deployer.deployment_steps)
|
| 115 |
]))
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
with gr.Column(scale=3):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# Step 1: Authentication
|
| 122 |
with gr.Group(visible=True) as step1:
|
| 123 |
gr.Markdown("### Step 1: Authenticate with Hugging Face")
|
|
@@ -344,8 +349,10 @@ def listen(audio):
|
|
| 344 |
chat_history = gr.Chatbot(label="Chat History", type="messages")
|
| 345 |
|
| 346 |
with gr.Row():
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
| 349 |
|
| 350 |
# Hidden components for processing
|
| 351 |
transcribed_text = gr.Textbox(visible=False)
|
|
@@ -378,13 +385,13 @@ def listen(audio):
|
|
| 378 |
success, message, user_info = deployer.authenticate(token)
|
| 379 |
if success:
|
| 380 |
models = deployer.get_available_models()
|
| 381 |
-
return message, gr.Dropdown(choices=models),
|
| 382 |
-
return message, gr.Dropdown(choices=[]),
|
| 383 |
|
| 384 |
auth_btn.click(
|
| 385 |
authenticate_user,
|
| 386 |
inputs=[hf_token],
|
| 387 |
-
outputs=[auth_status, user_models,
|
| 388 |
)
|
| 389 |
|
| 390 |
def show_step(step_num):
|
|
@@ -397,11 +404,11 @@ def listen(audio):
|
|
| 397 |
for i, step in enumerate(deployer.deployment_steps)
|
| 398 |
])
|
| 399 |
|
| 400 |
-
# Update
|
| 401 |
prev_disabled = step_num == 0
|
| 402 |
next_disabled = step_num == len(steps) - 1
|
| 403 |
|
| 404 |
-
return [step_display_text
|
| 405 |
|
| 406 |
def next_step(current_step):
|
| 407 |
if current_step < len(deployer.deployment_steps) - 1:
|
|
@@ -415,14 +422,25 @@ def listen(audio):
|
|
| 415 |
return show_step(current_step - 1)
|
| 416 |
return show_step(current_step)
|
| 417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
next_btn.click(
|
| 419 |
lambda: next_step(deployer.current_step),
|
| 420 |
-
outputs=[step_display,
|
|
|
|
|
|
|
|
|
|
| 421 |
)
|
| 422 |
|
| 423 |
prev_btn.click(
|
| 424 |
lambda: prev_step(deployer.current_step),
|
| 425 |
-
outputs=[step_display,
|
|
|
|
|
|
|
|
|
|
| 426 |
)
|
| 427 |
|
| 428 |
def handle_model_choice(choice):
|
|
@@ -475,9 +493,6 @@ def listen(audio):
|
|
| 475 |
return "❌ Please deploy a model first"
|
| 476 |
|
| 477 |
try:
|
| 478 |
-
# Extract endpoint name from URL
|
| 479 |
-
endpoint_name = endpoint_url.split("/")[-1]
|
| 480 |
-
|
| 481 |
# Use Hugging Face inference API
|
| 482 |
headers = {"Authorization": f"Bearer {deployer.current_token}"}
|
| 483 |
data = {
|
|
@@ -624,4 +639,14 @@ if __name__ == "__main__":
|
|
| 624 |
share=True,
|
| 625 |
show_error=True,
|
| 626 |
show_api=True
|
| 627 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
for i, step in enumerate(deployer.deployment_steps)
|
| 115 |
]))
|
| 116 |
|
| 117 |
+
with gr.Row():
|
| 118 |
+
prev_btn = gr.Button("⬅️ Previous")
|
| 119 |
+
next_btn = gr.Button("Next ➡️")
|
| 120 |
|
| 121 |
with gr.Column(scale=3):
|
| 122 |
+
# State for managing button visibility
|
| 123 |
+
prev_state = gr.State(value=True)
|
| 124 |
+
next_state = gr.State(value=False)
|
| 125 |
+
|
| 126 |
# Step 1: Authentication
|
| 127 |
with gr.Group(visible=True) as step1:
|
| 128 |
gr.Markdown("### Step 1: Authenticate with Hugging Face")
|
|
|
|
| 349 |
chat_history = gr.Chatbot(label="Chat History", type="messages")
|
| 350 |
|
| 351 |
with gr.Row():
|
| 352 |
+
with gr.Column():
|
| 353 |
+
tts_output = gr.Audio(label="Voice Response")
|
| 354 |
+
with gr.Column():
|
| 355 |
+
text_response = gr.Textbox(label="Text Response", lines=3)
|
| 356 |
|
| 357 |
# Hidden components for processing
|
| 358 |
transcribed_text = gr.Textbox(visible=False)
|
|
|
|
| 385 |
success, message, user_info = deployer.authenticate(token)
|
| 386 |
if success:
|
| 387 |
models = deployer.get_available_models()
|
| 388 |
+
return message, gr.Dropdown(choices=models), user_info
|
| 389 |
+
return message, gr.Dropdown(choices=[]), None
|
| 390 |
|
| 391 |
auth_btn.click(
|
| 392 |
authenticate_user,
|
| 393 |
inputs=[hf_token],
|
| 394 |
+
outputs=[auth_status, user_models, step1]
|
| 395 |
)
|
| 396 |
|
| 397 |
def show_step(step_num):
|
|
|
|
| 404 |
for i, step in enumerate(deployer.deployment_steps)
|
| 405 |
])
|
| 406 |
|
| 407 |
+
# Update button states
|
| 408 |
prev_disabled = step_num == 0
|
| 409 |
next_disabled = step_num == len(steps) - 1
|
| 410 |
|
| 411 |
+
return [step_display_text] + updates
|
| 412 |
|
| 413 |
def next_step(current_step):
|
| 414 |
if current_step < len(deployer.deployment_steps) - 1:
|
|
|
|
| 422 |
return show_step(current_step - 1)
|
| 423 |
return show_step(current_step)
|
| 424 |
|
| 425 |
+
def update_buttons(step_num):
|
| 426 |
+
prev_btn_text = "⬅️ Previous" if step_num > 0 else "⬅️ Previous"
|
| 427 |
+
next_btn_text = "Next ➡️" if step_num < len(deployer.deployment_steps) - 1 else "✅ Complete"
|
| 428 |
+
return prev_btn_text, next_btn_text
|
| 429 |
+
|
| 430 |
next_btn.click(
|
| 431 |
lambda: next_step(deployer.current_step),
|
| 432 |
+
outputs=[step_display, step1, step2, step3, step4, step5, step6]
|
| 433 |
+
).then(
|
| 434 |
+
lambda: update_buttons(deployer.current_step),
|
| 435 |
+
outputs=[prev_btn, next_btn]
|
| 436 |
)
|
| 437 |
|
| 438 |
prev_btn.click(
|
| 439 |
lambda: prev_step(deployer.current_step),
|
| 440 |
+
outputs=[step_display, step1, step2, step3, step4, step5, step6]
|
| 441 |
+
).then(
|
| 442 |
+
lambda: update_buttons(deployer.current_step),
|
| 443 |
+
outputs=[prev_btn, next_btn]
|
| 444 |
)
|
| 445 |
|
| 446 |
def handle_model_choice(choice):
|
|
|
|
| 493 |
return "❌ Please deploy a model first"
|
| 494 |
|
| 495 |
try:
|
|
|
|
|
|
|
|
|
|
| 496 |
# Use Hugging Face inference API
|
| 497 |
headers = {"Authorization": f"Bearer {deployer.current_token}"}
|
| 498 |
data = {
|
|
|
|
| 639 |
share=True,
|
| 640 |
show_error=True,
|
| 641 |
show_api=True
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
The main fix was removing the `disabled` parameter from the Button initialization since it's not supported in this version of Gradio. Instead, I've updated the button states through the event handlers to manage their functionality.
|
| 645 |
+
|
| 646 |
+
The key changes:
|
| 647 |
+
1. Removed `disabled=True` from button initialization
|
| 648 |
+
2. Added `update_buttons` function to manage button text and state
|
| 649 |
+
3. Updated the button click handlers to properly manage step navigation
|
| 650 |
+
4. Fixed the step visibility logic
|
| 651 |
+
|
| 652 |
+
This should now deploy successfully without the TypeError!
|
requirements.txt
CHANGED
|
@@ -1,13 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
huggingface_hub
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
scipy>=1.11.0
|
| 12 |
-
matplotlib>=3.7.0
|
| 13 |
-
pandas>=2.0.0
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/transformers
|
| 2 |
+
huggingface_hub
|
| 3 |
+
torch
|
| 4 |
+
spaces
|
| 5 |
+
gradio
|
| 6 |
+
requests
|
| 7 |
+
numpy
|
| 8 |
+
accelerate
|
| 9 |
+
tokenizers
|
| 10 |
+
sentencepiece
|
|
|
|
|
|
|
|
|