Spaces:
Sleeping
Sleeping
| import os | |
| # Create the app folder if it doesn't exist | |
| os.makedirs('/content/BCCD-object/app', exist_ok=True) | |
| # Define the Gradio app code | |
| app_code = """ | |
| import gradio as gr | |
| from ultralytics import YOLO | |
| from PIL import Image | |
| # Load the trained model | |
| model = YOLO('/content/BCCD-object/model/bccd_yolov8.pt') | |
| # Prediction function | |
| def predict(image): | |
| results = model(image) | |
| annotated_image = results[0].plot() # Draw bounding boxes | |
| return Image.fromarray(annotated_image) | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Image(type="pil"), | |
| title="BCCD Object Detection", | |
| description="Upload an image to detect RBC, WBC, and Platelets.", | |
| ) | |
| # Launch the app | |
| iface.launch(share=True) | |
| """ | |
| # Save the code to app.py | |
| with open('/content/BCCD-object/app/app.py', 'w') as f: | |
| f.write(app_code) | |