Satyacoder commited on
Commit
c668c43
·
1 Parent(s): dd3ad6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -10,7 +10,7 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
10
  def predict_bounding_boxes(imageurl:str):
11
  try:
12
  response = requests.get(imageurl, stream=True)
13
- response.raise_for_status() # Raise an exception for HTTP errors
14
 
15
  image_data = Image.open(response.raw)
16
  inputs = processor(images=image_data, return_tensors="pt")
@@ -21,11 +21,10 @@ def predict_bounding_boxes(imageurl:str):
21
 
22
  detections = [{"score": score.item(), "label": model.config.id2label[label.item()], "box": box.tolist()} for score, label, box in zip(results["scores"], results["labels"], results["boxes"])]
23
 
24
- # Wrap detections list inside a dictionary
25
  return {"detections": detections}
26
 
27
  except Exception as e:
28
- # Handle errors gracefully
29
  return {"error": str(e)}
30
 
31
  app = gr.Interface(fn=predict_bounding_boxes, inputs="text", outputs="json")
 
10
  def predict_bounding_boxes(imageurl:str):
11
  try:
12
  response = requests.get(imageurl, stream=True)
13
+ response.raise_for_status()
14
 
15
  image_data = Image.open(response.raw)
16
  inputs = processor(images=image_data, return_tensors="pt")
 
21
 
22
  detections = [{"score": score.item(), "label": model.config.id2label[label.item()], "box": box.tolist()} for score, label, box in zip(results["scores"], results["labels"], results["boxes"])]
23
 
 
24
  return {"detections": detections}
25
 
26
  except Exception as e:
27
+
28
  return {"error": str(e)}
29
 
30
  app = gr.Interface(fn=predict_bounding_boxes, inputs="text", outputs="json")