File size: 907 Bytes
8f5eb48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)