frncscp commited on
Commit
65176bd
·
1 Parent(s): bd81858

Update pages/Entorno de Ejecución.py

Browse files
Files changed (1) hide show
  1. pages/Entorno de Ejecución.py +8 -4
pages/Entorno de Ejecución.py CHANGED
@@ -50,7 +50,8 @@ headers = {"Authorization": f"Bearer {st.secrets['token']}"}
50
 
51
  def query(data, models): #HF API
52
  response = requests.post(API_URL + "/" + model_name, headers=headers, data=data)
53
- st.write(response.json())
 
54
  while "error" in response.json():
55
  response = requests.post(API_URL + "/" + model_name, headers=headers, data=data)
56
  return response.json()[1]["score"] #.json
@@ -176,15 +177,15 @@ with vit:
176
  elif uploaded_file is not None:
177
  with st.spinner('Cargando predicción...'):
178
 
179
- y_gorritoo = query(uploaded_file.read(), model_dict[model_choice[0]])
180
- st.write(y_gorritoo)
181
  #classifiers = [pipeline("image-classification", model= model_dict[model_choice[i]]) for i in range(len(model_choice))]
182
 
183
  #classifier = pipeline("image-classification", model= model_dict[model_choice[0]])
184
  img = preprocess(uploaded_file, module = 'pil')
185
 
186
  models = [model_dict[model] for model in model_choice]
187
- st.write(models)
188
  #def vit_ensemble(classifier_list, img):
189
  # y_gorrito = 0
190
  # for classifier in classifier_list:
@@ -207,6 +208,9 @@ with vit:
207
  i+=1
208
  st.write("y gorrito a cargar")
209
  a = query(uploaded_file.read(), model)
 
 
 
210
  st.write("query terminado")
211
  y_gorrito += a
212
  st.write("y gorrito cargado")
 
50
 
51
  def query(data, models): #HF API
52
  response = requests.post(API_URL + "/" + model_name, headers=headers, data=data)
53
+ if response.json()["error"] == "Internal Server Error":
54
+ return -1
55
  while "error" in response.json():
56
  response = requests.post(API_URL + "/" + model_name, headers=headers, data=data)
57
  return response.json()[1]["score"] #.json
 
177
  elif uploaded_file is not None:
178
  with st.spinner('Cargando predicción...'):
179
 
180
+ #y_gorritoo = query(uploaded_file.read(), model_dict[model_choice[0]])
181
+ #st.write(y_gorritoo)
182
  #classifiers = [pipeline("image-classification", model= model_dict[model_choice[i]]) for i in range(len(model_choice))]
183
 
184
  #classifier = pipeline("image-classification", model= model_dict[model_choice[0]])
185
  img = preprocess(uploaded_file, module = 'pil')
186
 
187
  models = [model_dict[model] for model in model_choice]
188
+ #st.write(models)
189
  #def vit_ensemble(classifier_list, img):
190
  # y_gorrito = 0
191
  # for classifier in classifier_list:
 
208
  i+=1
209
  st.write("y gorrito a cargar")
210
  a = query(uploaded_file.read(), model)
211
+ if a == -1:
212
+ st.write("Los servidores se encuentrar caídos, intente más tarde")
213
+ break
214
  st.write("query terminado")
215
  y_gorrito += a
216
  st.write("y gorrito cargado")