Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,8 @@ def detect_objects(image, score_threshold):
|
|
| 20 |
target_sizes = torch.tensor([image.size[::-1]])
|
| 21 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes)
|
| 22 |
|
|
|
|
|
|
|
| 23 |
# Draw bounding boxes around detected objects
|
| 24 |
draw = ImageDraw.Draw(image)
|
| 25 |
for result in results:
|
|
@@ -33,14 +35,16 @@ def detect_objects(image, score_threshold):
|
|
| 33 |
label_name = "Pneumonia" if label.item() == 0 else "Other"
|
| 34 |
draw.rectangle(box, outline="red", width=3)
|
| 35 |
draw.text((box[0], box[1]), f"{label_name}: {round(score.item(), 3)}", fill="red")
|
|
|
|
| 36 |
|
| 37 |
-
return image
|
| 38 |
|
| 39 |
# Create the Gradio interface
|
| 40 |
interface = gr.Interface(
|
| 41 |
fn=detect_objects,
|
| 42 |
inputs=[gr.Image(type="pil"), gr.Slider(0, 1, value=0.5, label="Score Threshold")], # Add slider for score threshold
|
| 43 |
-
outputs=gr.Image(type="pil"), # Corrected output type
|
|
|
|
| 44 |
title="Object Detection with Transformers",
|
| 45 |
description="Upload an image to detect objects using a fine-tuned Conditional-DETR model."
|
| 46 |
)
|
|
|
|
| 20 |
target_sizes = torch.tensor([image.size[::-1]])
|
| 21 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes)
|
| 22 |
|
| 23 |
+
labels_output = []
|
| 24 |
+
|
| 25 |
# Draw bounding boxes around detected objects
|
| 26 |
draw = ImageDraw.Draw(image)
|
| 27 |
for result in results:
|
|
|
|
| 35 |
label_name = "Pneumonia" if label.item() == 0 else "Other"
|
| 36 |
draw.rectangle(box, outline="red", width=3)
|
| 37 |
draw.text((box[0], box[1]), f"{label_name}: {round(score.item(), 3)}", fill="red")
|
| 38 |
+
labels_output.append(f"{label_name}: {round(score.item(), 3)}")
|
| 39 |
|
| 40 |
+
return image, "\n".join(labels_output)
|
| 41 |
|
| 42 |
# Create the Gradio interface
|
| 43 |
interface = gr.Interface(
|
| 44 |
fn=detect_objects,
|
| 45 |
inputs=[gr.Image(type="pil"), gr.Slider(0, 1, value=0.5, label="Score Threshold")], # Add slider for score threshold
|
| 46 |
+
# outputs=gr.Image(type="pil"), # Corrected output type
|
| 47 |
+
outputs=[gr.Image(type="pil"), gr.Textbox(label="Detected Objects")],
|
| 48 |
title="Object Detection with Transformers",
|
| 49 |
description="Upload an image to detect objects using a fine-tuned Conditional-DETR model."
|
| 50 |
)
|