Improving verbosity. Adding checks for missing URL.
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from Gradio_UI import GradioUI
|
|
10 |
|
11 |
verbose = True
|
12 |
|
13 |
-
if verbose: print("Running app.py
|
14 |
|
15 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
16 |
@tool
|
@@ -82,7 +82,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
82 |
|
83 |
final_answer = FinalAnswerTool()
|
84 |
|
85 |
-
if verbose: print("Defining MODEL_IDS
|
86 |
|
87 |
MODEL_IDS = [
|
88 |
'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
|
@@ -99,6 +99,8 @@ def is_model_overloaded(model_url):
|
|
99 |
response = requests.post(model_url, json={"inputs": "Test"})
|
100 |
if response.status_code == 503: # 503 Service Unavailable = Overloaded
|
101 |
return True
|
|
|
|
|
102 |
return False
|
103 |
except requests.RequestException:
|
104 |
return True # if there are an error is overloaded
|
@@ -106,12 +108,12 @@ def is_model_overloaded(model_url):
|
|
106 |
def get_available_model():
|
107 |
"""Select the first model available from the list."""
|
108 |
for model_url in MODEL_IDS:
|
109 |
-
print("trying",model_url,"\n")
|
110 |
if not is_model_overloaded(model_url):
|
111 |
return model_url
|
112 |
return MODEL_IDS[0] # if all are failing, use the first model by dfault
|
113 |
|
114 |
-
if verbose: print("Checking available models
|
115 |
|
116 |
selected_model_id = get_available_model()
|
117 |
|
|
|
10 |
|
11 |
verbose = True
|
12 |
|
13 |
+
if verbose: print("Running app.py.\n")
|
14 |
|
15 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
16 |
@tool
|
|
|
82 |
|
83 |
final_answer = FinalAnswerTool()
|
84 |
|
85 |
+
if verbose: print("Defining MODEL_IDS.\n")
|
86 |
|
87 |
MODEL_IDS = [
|
88 |
'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
|
|
|
99 |
response = requests.post(model_url, json={"inputs": "Test"})
|
100 |
if response.status_code == 503: # 503 Service Unavailable = Overloaded
|
101 |
return True
|
102 |
+
if response.status_code == 404: # 404 Client Error: Not Found
|
103 |
+
return True
|
104 |
return False
|
105 |
except requests.RequestException:
|
106 |
return True # if there are an error is overloaded
|
|
|
108 |
def get_available_model():
|
109 |
"""Select the first model available from the list."""
|
110 |
for model_url in MODEL_IDS:
|
111 |
+
print(" trying",model_url,"\n")
|
112 |
if not is_model_overloaded(model_url):
|
113 |
return model_url
|
114 |
return MODEL_IDS[0] # if all are failing, use the first model by dfault
|
115 |
|
116 |
+
if verbose: print("Checking available models.\n")
|
117 |
|
118 |
selected_model_id = get_available_model()
|
119 |
|