wuhp commited on
Commit
32de25b
·
verified ·
1 Parent(s): 6f44956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -7,6 +7,17 @@ import requests
7
  import logging
8
  from typing import List, Dict, Any, Tuple, Optional, Literal, Generator, Union # Import Union for clarity
9
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # --- Configure Logging ---
12
  # Replace print() statements with logging
@@ -1390,7 +1401,8 @@ def handle_complete(
1390
 
1391
 
1392
  # --- Dispatch Table ---
1393
- STATE_HANDLERS: Dict[WorkflowState, Any] = { # Use Any for type hint simplicity here
 
1394
  STATE_IDLE: handle_idle,
1395
  STATE_AWAITING_REPO_NAME: handle_awaiting_repo_name,
1396
  STATE_CREATING_SPACE: handle_creating_space,
@@ -1433,7 +1445,7 @@ def ai_workflow_chat(
1433
  # Accept any extra args/kwargs passed by Gradio, common for generators
1434
  *args,
1435
  **kwargs
1436
- ) -> Any: # Use Any because it yields multiple times before returning the final value (None in this case)
1437
  """
1438
  Generator function to handle the AI workflow state machine.
1439
  Each 'yield' pauses execution and sends values to update Gradio outputs/state.
 
7
  import logging
8
  from typing import List, Dict, Any, Tuple, Optional, Literal, Generator, Union # Import Union for clarity
9
 
10
+ import gradio as gr
11
+ import google.generativeai as genai
12
+ from google.generativeai import types # Import types for configuration and tools
13
+
14
+ from huggingface_hub import create_repo, list_models, upload_file, constants
15
+ from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
16
+
17
+ # --- Import for Hugging Face API Retries ---
18
+ from requests.adapters import HTTPAdapter
19
+ from urllib3.util.retry import Retry # <-- Ensure this line is present and NOT commented out
20
+
21
 
22
  # --- Configure Logging ---
23
  # Replace print() statements with logging
 
1401
 
1402
 
1403
  # --- Dispatch Table ---
1404
+ # Using Union for the return type hint in the Dict value type for clarity
1405
+ STATE_HANDLERS: Dict[WorkflowState, Union[WorkflowOutputs, Generator[WorkflowOutputs, None, WorkflowOutputs]]] = {
1406
  STATE_IDLE: handle_idle,
1407
  STATE_AWAITING_REPO_NAME: handle_awaiting_repo_name,
1408
  STATE_CREATING_SPACE: handle_creating_space,
 
1445
  # Accept any extra args/kwargs passed by Gradio, common for generators
1446
  *args,
1447
  **kwargs
1448
+ ) -> Generator[WorkflowOutputs, None, None]: # Correct return type for the main generator
1449
  """
1450
  Generator function to handle the AI workflow state machine.
1451
  Each 'yield' pauses execution and sends values to update Gradio outputs/state.