davanstrien HF staff commited on
Commit
afe6a3f
·
1 Parent(s): 96baeb1

catch httpx.ConnectError

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -45,7 +45,7 @@ async def get_image(client, url):
45
  try:
46
  resp = await client.get(url, timeout=30)
47
  return Image.open(io.BytesIO(resp.content))
48
- except (PIL.UnidentifiedImageError, httpx.ReadTimeout):
49
  return None
50
 
51
 
@@ -66,8 +66,7 @@ def predict(inputs):
66
  top_pred = classif_pipeline(image, top_k=1)[0]
67
  if top_pred['label'] == 'illustrated':
68
  predicted_images.append((image, top_pred['score']))
69
- if len(predicted_images):
70
- return predicted_images
71
 
72
 
73
  demo = gr.Interface(
 
45
  try:
46
  resp = await client.get(url, timeout=30)
47
  return Image.open(io.BytesIO(resp.content))
48
+ except (PIL.UnidentifiedImageError, httpx.ReadTimeout, httpx.ConnectError):
49
  return None
50
 
51
 
 
66
  top_pred = classif_pipeline(image, top_k=1)[0]
67
  if top_pred['label'] == 'illustrated':
68
  predicted_images.append((image, top_pred['score']))
69
+ return predicted_images
 
70
 
71
 
72
  demo = gr.Interface(