Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,7 @@ model = YOLO("yolov8x-doclaynet-epoch64-imgsz640-initiallr1e-4-finallr1e-5.pt")
|
|
| 9 |
# Get class names from model
|
| 10 |
class_names = model.names
|
| 11 |
|
| 12 |
-
|
| 13 |
-
@spaces.GPU(duration=60)
|
| 14 |
def process_image(image):
|
| 15 |
try:
|
| 16 |
# Process the image
|
|
@@ -22,16 +21,16 @@ def process_image(image):
|
|
| 22 |
|
| 23 |
# Use cls attribute for labels and get class name from model
|
| 24 |
detected_areas_labels = "\n".join([
|
| 25 |
-
f"{class_names[int(box.cls.item())].upper()}: {box.conf:.2f}" for box in result.boxes
|
| 26 |
])
|
| 27 |
|
| 28 |
return annotated_image, detected_areas_labels
|
| 29 |
except Exception as e:
|
| 30 |
-
return None, f"Error processing image: {e}"
|
| 31 |
|
| 32 |
# Create the Gradio Interface
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
-
gr.Markdown("# Document Segmentation Demo (ZeroGPU)")
|
| 35 |
# Input Components
|
| 36 |
input_image = gr.Image(type="pil", label="Upload Image")
|
| 37 |
|
|
@@ -44,4 +43,4 @@ with gr.Blocks() as demo:
|
|
| 44 |
btn.click(fn=process_image, inputs=input_image, outputs=[output_image, output_text])
|
| 45 |
|
| 46 |
# Launch the demo with queuing
|
| 47 |
-
demo.queue(max_size=1).launch()
|
|
|
|
| 9 |
# Get class names from model
|
| 10 |
class_names = model.names
|
| 11 |
|
| 12 |
+
@spaces.GPU(duration=60)
|
|
|
|
| 13 |
def process_image(image):
|
| 14 |
try:
|
| 15 |
# Process the image
|
|
|
|
| 21 |
|
| 22 |
# Use cls attribute for labels and get class name from model
|
| 23 |
detected_areas_labels = "\n".join([
|
| 24 |
+
f"{class_names[int(box.cls.item())].upper()}: {float(box.conf):.2f}" for box in result.boxes
|
| 25 |
])
|
| 26 |
|
| 27 |
return annotated_image, detected_areas_labels
|
| 28 |
except Exception as e:
|
| 29 |
+
return None, f"Error processing image: {e}"
|
| 30 |
|
| 31 |
# Create the Gradio Interface
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown("# Document Segmentation Demo (ZeroGPU)")
|
| 34 |
# Input Components
|
| 35 |
input_image = gr.Image(type="pil", label="Upload Image")
|
| 36 |
|
|
|
|
| 43 |
btn.click(fn=process_image, inputs=input_image, outputs=[output_image, output_text])
|
| 44 |
|
| 45 |
# Launch the demo with queuing
|
| 46 |
+
demo.queue(max_size=1).launch()
|