Spaces:
Paused
Paused
ai: Implement Gradio custom error handling and display on frontend.
Browse files* Improves user feedback by providing clear error notifications during failures.
* And, "!fixup: ai: Use server-side queuing implementation."
--> 3949dad46f6dc0c1a4bff34676007251edb66c4e
- app.py +1 -1
- src/core/server.py +2 -2
- src/ui/interface.py +2 -1
- src/utils/session_mapping.py +3 -1
- src/utils/tools.py +5 -2
app.py
CHANGED
|
@@ -16,4 +16,4 @@ if __name__ == "__main__":
|
|
| 16 |
|
| 17 |
# Call the 'launch' method on the 'app' object to start the user interface.
|
| 18 |
# This typically opens the UI window or begins the event loop, making the application interactive.
|
| 19 |
-
app.queue(default_concurrency_limit=None).launch(share=True,
|
|
|
|
| 16 |
|
| 17 |
# Call the 'launch' method on the 'app' object to start the user interface.
|
| 18 |
# This typically opens the UI window or begins the event loop, making the application interactive.
|
| 19 |
+
app.queue(default_concurrency_limit=None).launch(share=True, pwa=True)
|
src/core/server.py
CHANGED
|
@@ -123,6 +123,6 @@ async def jarvis(
|
|
| 123 |
except Exception: # Catch generic exceptions to avoid crashing
|
| 124 |
mark(server) # Mark fallback server as failed
|
| 125 |
|
| 126 |
-
# If all servers have been tried and failed,
|
| 127 |
-
yield "The server is currently busy. Please wait a moment or try again later" # Inform user of service unavailability
|
| 128 |
return # End the function after exhausting all servers
|
|
|
|
| 123 |
except Exception: # Catch generic exceptions to avoid crashing
|
| 124 |
mark(server) # Mark fallback server as failed
|
| 125 |
|
| 126 |
+
# If all servers have been tried and failed, show the error message
|
| 127 |
+
yield {"role": "assistant", "content": "The server is currently busy. Please wait a moment or try again later"} # Inform user of service unavailability
|
| 128 |
return # End the function after exhausting all servers
|
src/ui/interface.py
CHANGED
|
@@ -182,7 +182,8 @@ def ui():
|
|
| 182 |
fill_width=True, # Duplicate from Blocks to Chat Interface
|
| 183 |
head=meta_tags, # Duplicate from Blocks to Chat Interface
|
| 184 |
show_progress="full", # Progress animation
|
| 185 |
-
api_name="api" # API endpoint
|
|
|
|
| 186 |
)
|
| 187 |
# Return the complete Gradio app object for launching or embedding
|
| 188 |
return app
|
|
|
|
| 182 |
fill_width=True, # Duplicate from Blocks to Chat Interface
|
| 183 |
head=meta_tags, # Duplicate from Blocks to Chat Interface
|
| 184 |
show_progress="full", # Progress animation
|
| 185 |
+
api_name="api", # API endpoint
|
| 186 |
+
concurrency_limit=None # Queuing
|
| 187 |
)
|
| 188 |
# Return the complete Gradio app object for launching or embedding
|
| 189 |
return app
|
src/utils/session_mapping.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
#
|
| 5 |
|
| 6 |
import random # Import random module to enable random selection from a list
|
|
|
|
| 7 |
from datetime import datetime # Import datetime class to work with current UTC time
|
| 8 |
from typing import Dict, List # Import type hints for dictionaries and lists (not explicitly used here but imported)
|
| 9 |
from config import auth # Import authentication configuration, likely a list of host dictionaries with credentials
|
|
@@ -59,7 +60,8 @@ def get_host(session_id: str, exclude_hosts: List[str] = None) -> dict:
|
|
| 59 |
|
| 60 |
# If no hosts are available after filtering, raise an exception to indicate resource exhaustion
|
| 61 |
if not available_hosts: # Check if the filtered list of hosts is empty
|
| 62 |
-
raise
|
|
|
|
| 63 |
|
| 64 |
# Randomly select one host from the list of available hosts to distribute load evenly
|
| 65 |
selected = random.choice(available_hosts) # Choose a host at random to avoid bias in host selection
|
|
|
|
| 4 |
#
|
| 5 |
|
| 6 |
import random # Import random module to enable random selection from a list
|
| 7 |
+
import gradio as gr # Import the Gradio library to build interactive web interfaces for machine learning applications
|
| 8 |
from datetime import datetime # Import datetime class to work with current UTC time
|
| 9 |
from typing import Dict, List # Import type hints for dictionaries and lists (not explicitly used here but imported)
|
| 10 |
from config import auth # Import authentication configuration, likely a list of host dictionaries with credentials
|
|
|
|
| 60 |
|
| 61 |
# If no hosts are available after filtering, raise an exception to indicate resource exhaustion
|
| 62 |
if not available_hosts: # Check if the filtered list of hosts is empty
|
| 63 |
+
raise gr.Error("The server is currently busy. Please wait a moment or try again later", duration=5, title="INFO")
|
| 64 |
+
# Inform user of service unavailability
|
| 65 |
|
| 66 |
# Randomly select one host from the list of available hosts to distribute load evenly
|
| 67 |
selected = random.choice(available_hosts) # Choose a host at random to avoid bias in host selection
|
src/utils/tools.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
#
|
| 5 |
|
| 6 |
import random # Import random module to enable random selection from a list
|
|
|
|
| 7 |
from datetime import datetime # Import datetime class to work with current UTC time
|
| 8 |
from config import auth # Import authentication configuration, likely a list of host dictionaries with credentials
|
| 9 |
from src.utils.helper import busy, mark # Import 'busy' dictionary and 'mark' function to track and update host busy status
|
|
@@ -39,7 +40,8 @@ def initialize_tools():
|
|
| 39 |
|
| 40 |
# Raise an exception if no hosts are currently available
|
| 41 |
if not available:
|
| 42 |
-
raise
|
|
|
|
| 43 |
|
| 44 |
# Randomly select one host from the available list
|
| 45 |
selected = random.choice(available)
|
|
@@ -55,7 +57,8 @@ def initialize_tools():
|
|
| 55 |
|
| 56 |
# Verify that all required tool endpoints are present, raise exception if any is missing
|
| 57 |
if not tool_setup or not image_tool or not audio_tool or not poll_token:
|
| 58 |
-
raise
|
|
|
|
| 59 |
|
| 60 |
# Return the three tool endpoints as a tuple
|
| 61 |
return tool_setup, image_tool, audio_tool, poll_token
|
|
|
|
| 4 |
#
|
| 5 |
|
| 6 |
import random # Import random module to enable random selection from a list
|
| 7 |
+
import gradio as gr # Import the Gradio library to build interactive web interfaces for machine learning applications
|
| 8 |
from datetime import datetime # Import datetime class to work with current UTC time
|
| 9 |
from config import auth # Import authentication configuration, likely a list of host dictionaries with credentials
|
| 10 |
from src.utils.helper import busy, mark # Import 'busy' dictionary and 'mark' function to track and update host busy status
|
|
|
|
| 40 |
|
| 41 |
# Raise an exception if no hosts are currently available
|
| 42 |
if not available:
|
| 43 |
+
raise gr.Error("The server is currently busy. Please wait a moment or try again later", duration=5, title="INFO")
|
| 44 |
+
# Inform user of service unavailability
|
| 45 |
|
| 46 |
# Randomly select one host from the available list
|
| 47 |
selected = random.choice(available)
|
|
|
|
| 57 |
|
| 58 |
# Verify that all required tool endpoints are present, raise exception if any is missing
|
| 59 |
if not tool_setup or not image_tool or not audio_tool or not poll_token:
|
| 60 |
+
raise gr.Error("The server is currently busy. Please wait a moment or try again later", duration=5, title="INFO")
|
| 61 |
+
# Inform user of service unavailability
|
| 62 |
|
| 63 |
# Return the three tool endpoints as a tuple
|
| 64 |
return tool_setup, image_tool, audio_tool, poll_token
|