tech5 commited on
Commit
ed5a35c
·
verified ·
1 Parent(s): 10d292b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -36
app.py CHANGED
@@ -1,36 +1,23 @@
1
- import os
2
-
3
- # Create the app folder if it doesn't exist
4
- os.makedirs('/content/BCCD-object/app', exist_ok=True)
5
-
6
- # Define the Gradio app code
7
- app_code = """
8
- import gradio as gr
9
- from ultralytics import YOLO
10
- from PIL import Image
11
-
12
- # Load the trained model
13
- model = YOLO('/content/BCCD-object/model/bccd_yolov8.pt')
14
-
15
- # Prediction function
16
- def predict(image):
17
- results = model(image)
18
- annotated_image = results[0].plot() # Draw bounding boxes
19
- return Image.fromarray(annotated_image)
20
-
21
- # Gradio Interface
22
- iface = gr.Interface(
23
- fn=predict,
24
- inputs=gr.Image(type="pil"),
25
- outputs=gr.Image(type="pil"),
26
- title="BCCD Object Detection",
27
- description="Upload an image to detect RBC, WBC, and Platelets.",
28
- )
29
-
30
- # Launch the app
31
- iface.launch(share=True)
32
- """
33
-
34
- # Save the code to app.py
35
- with open('/content/BCCD-object/app/app.py', 'w') as f:
36
- f.write(app_code)
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+
5
+ # Load the trained model
6
+ model = YOLO('bccd_yolov8.pt') # Make sure the model file is in the same folder as app.py
7
+
8
+ # Prediction function
9
+ def predict(image):
10
+ results = model(image)
11
+ annotated_image = results[0].plot() # Draw bounding boxes
12
+ return Image.fromarray(annotated_image)
13
+
14
+ # Gradio Interface
15
+ iface = gr.Interface(
16
+ fn=predict,
17
+ inputs=gr.Image(type="pil"),
18
+ outputs=gr.Image(type="pil"),
19
+ title="BCCD Object Detection",
20
+ description="Upload an image to detect RBC, WBC, and Platelets.",
21
+ )
22
+
23
+ iface.launch()