Spaces:
Runtime error
Runtime error
update output
Browse files
app.py
CHANGED
|
@@ -15,20 +15,21 @@ import spaces
|
|
| 15 |
hf_token = os.getenv("HF_TOKEN")
|
| 16 |
login(token=hf_token, add_to_git_credential=True)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
-
Detects a brain tumor in the given image and
|
| 21 |
|
| 22 |
Parameters:
|
| 23 |
-
image: The input image (as provided by Gradio).
|
|
|
|
| 24 |
debug (bool): Flag to enable logging for debugging purposes.
|
| 25 |
|
| 26 |
Returns:
|
| 27 |
-
|
| 28 |
"""
|
| 29 |
-
# Generate a unique output filename
|
| 30 |
-
output_path = f"./output/tumor_detection_{int(time.time())}.jpg"
|
| 31 |
-
|
| 32 |
if debug:
|
| 33 |
print(f"Image received")
|
| 34 |
|
|
@@ -43,12 +44,20 @@ def detect_brain_tumor(image, debug: bool = False) -> str:
|
|
| 43 |
if debug:
|
| 44 |
print("Bounding boxes overlaid on the image")
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
INTRO_TEXT="# 🔬🧠 CellVision AI -- Intelligent Cell Imaging Analysis 🤖🧫"
|
| 54 |
IMAGE_PROMPT="Are these cells healthy or cancerous?"
|
|
@@ -59,7 +68,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column():
|
| 61 |
image = gr.Image(type="numpy")
|
| 62 |
-
seg_input = gr.Text(label="Entities to Segment/Detect")
|
| 63 |
|
| 64 |
with gr.Column():
|
| 65 |
annotated_image = gr.AnnotatedImage(label="Output")
|
|
|
|
| 15 |
hf_token = os.getenv("HF_TOKEN")
|
| 16 |
login(token=hf_token, add_to_git_credential=True)
|
| 17 |
|
| 18 |
+
import numpy as np
|
| 19 |
+
from PIL import Image
|
| 20 |
+
|
| 21 |
+
def detect_brain_tumor(image, seg_input, debug: bool = False):
|
| 22 |
"""
|
| 23 |
+
Detects a brain tumor in the given image and returns the annotated image.
|
| 24 |
|
| 25 |
Parameters:
|
| 26 |
+
image: The input image (as numpy array provided by Gradio).
|
| 27 |
+
seg_input: The segmentation input (not used in this function, but required for Gradio).
|
| 28 |
debug (bool): Flag to enable logging for debugging purposes.
|
| 29 |
|
| 30 |
Returns:
|
| 31 |
+
tuple: (numpy array of image, list of (label, score, bbox) tuples)
|
| 32 |
"""
|
|
|
|
|
|
|
|
|
|
| 33 |
if debug:
|
| 34 |
print(f"Image received")
|
| 35 |
|
|
|
|
| 44 |
if debug:
|
| 45 |
print("Bounding boxes overlaid on the image")
|
| 46 |
|
| 47 |
+
# Prepare annotations for AnnotatedImage output
|
| 48 |
+
annotations = []
|
| 49 |
+
for detection in detections:
|
| 50 |
+
label = detection['label']
|
| 51 |
+
score = detection['score']
|
| 52 |
+
bbox = detection['bbox']
|
| 53 |
+
x1, y1, x2, y2 = bbox
|
| 54 |
+
annotations.append((f"{label} {score:.2f}", (x1, y1, x2-x1, y2-y1)))
|
| 55 |
+
|
| 56 |
+
# Convert image to numpy array if it's not already
|
| 57 |
+
if isinstance(image_with_bboxes, Image.Image):
|
| 58 |
+
image_with_bboxes = np.array(image_with_bboxes)
|
| 59 |
+
|
| 60 |
+
return (image_with_bboxes, annotations)
|
| 61 |
|
| 62 |
INTRO_TEXT="# 🔬🧠 CellVision AI -- Intelligent Cell Imaging Analysis 🤖🧫"
|
| 63 |
IMAGE_PROMPT="Are these cells healthy or cancerous?"
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
image = gr.Image(type="numpy")
|
| 71 |
+
seg_input = gr.Text(label="Entities to Segment/Detect", value="detect brain tumor")
|
| 72 |
|
| 73 |
with gr.Column():
|
| 74 |
annotated_image = gr.AnnotatedImage(label="Output")
|