Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
verbose = True
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
|
@@ -51,23 +51,24 @@ def is_model_overloaded(model_url):
|
|
| 51 |
"""Verify if the model is overloaded doing a test call."""
|
| 52 |
try:
|
| 53 |
response = requests.post(model_url, json={"inputs": "Test"})
|
| 54 |
-
if verbose:
|
| 55 |
-
print(
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if response.status_code
|
| 59 |
-
return True
|
| 60 |
-
if response.status_code == 424: # 424 Client Error: Failed Dependency for url:
|
| 61 |
return True
|
| 62 |
return False
|
| 63 |
-
except requests.RequestException:
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def get_available_model():
|
| 67 |
"""Select the first model available from the list."""
|
| 68 |
for model_url in MODEL_IDS:
|
| 69 |
print("trying",model_url)
|
| 70 |
-
if not is_model_overloaded(model_url):
|
| 71 |
return model_url
|
| 72 |
return MODEL_IDS[0] # if all are failing, use the first model by default
|
| 73 |
|
|
@@ -75,6 +76,8 @@ if verbose: print("Checking available models.")
|
|
| 75 |
|
| 76 |
selected_model_id = get_available_model()
|
| 77 |
|
|
|
|
|
|
|
| 78 |
model = HfApiModel(
|
| 79 |
max_tokens=1048,
|
| 80 |
temperature=0.5,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
global verbose = True
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
|
|
|
| 51 |
"""Verify if the model is overloaded doing a test call."""
|
| 52 |
try:
|
| 53 |
response = requests.post(model_url, json={"inputs": "Test"})
|
| 54 |
+
if verbose:
|
| 55 |
+
print(f"URL: {model_url}")
|
| 56 |
+
print(f"Response Status Code: {response.status_code}")
|
| 57 |
+
|
| 58 |
+
if response.status_code in [503, 404, 424]:
|
|
|
|
|
|
|
| 59 |
return True
|
| 60 |
return False
|
| 61 |
+
except requests.RequestException as e:
|
| 62 |
+
if verbose:
|
| 63 |
+
print(f"Error accessing {model_url}: {e}")
|
| 64 |
+
return True # If there is an error, consider it overloaded
|
| 65 |
+
|
| 66 |
|
| 67 |
def get_available_model():
|
| 68 |
"""Select the first model available from the list."""
|
| 69 |
for model_url in MODEL_IDS:
|
| 70 |
print("trying",model_url)
|
| 71 |
+
if not is_model_overloaded(model_url)):
|
| 72 |
return model_url
|
| 73 |
return MODEL_IDS[0] # if all are failing, use the first model by default
|
| 74 |
|
|
|
|
| 76 |
|
| 77 |
selected_model_id = get_available_model()
|
| 78 |
|
| 79 |
+
if verbose: print("Using model {selected_model_id}")
|
| 80 |
+
|
| 81 |
model = HfApiModel(
|
| 82 |
max_tokens=1048,
|
| 83 |
temperature=0.5,
|