xgenatiik commited on
Commit
b5e2637
·
verified ·
1 Parent(s): 11ceb43

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +48 -0
  2. best.pt +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load YOLO model
7
+ model = YOLO("best.pt")
8
+
9
+ # Define the prediction function
10
+ def detect_species(files):
11
+ """
12
+ Detect species in uploaded images using the YOLO model.
13
+
14
+ Args:
15
+ files (list): List of uploaded image files.
16
+
17
+ Returns:
18
+ list: Annotated images or error messages for each file.
19
+ """
20
+ annotated_images = []
21
+ for file in files: # Loop through the list of uploaded files
22
+ try:
23
+ # Open and process the image
24
+ image = Image.open(file)
25
+ image = np.array(image) # Convert to numpy array
26
+ results = model(image) # Run the YOLO model
27
+ annotated_image = results[0].plot() # Generate annotated image
28
+ annotated_images.append(annotated_image) # Add to results
29
+ except Exception as e:
30
+ # Handle errors (e.g., unsupported or corrupt files)
31
+ error_message = f"Error processing file {file.name}: {str(e)}"
32
+ print(error_message) # Log the error
33
+ annotated_images.append(np.zeros((100, 100, 3))) # Placeholder image
34
+ return annotated_images
35
+
36
+ # Create the Gradio app
37
+ app = gr.Interface(
38
+ fn=detect_species,
39
+ inputs=gr.Files(file_types=["image"], label="Upload Images"), # Allow multiple image uploads
40
+ outputs=gr.Gallery(label="Detection Results"), # Display results in a gallery
41
+ title="Plant Species Detector",
42
+ description="Upload one or more leaf images, and the model will detect the species.",
43
+ examples=["example1.jpg", "example2.jpg"], # Optional: Add example images
44
+ )
45
+
46
+ # Launch the app
47
+ if __name__ == "__main__":
48
+ app.launch(share=True) # Set share=True to get a public URL
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40cf469a5957a0bee78266cde69c7a63dcedb12ec9cb75d3b174a2dec526981e
3
+ size 19196051
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==4.44.1
2
+ ultralytics==8.3.40
3
+ numpy<2.0,>=1.26.0
4
+ pillow<11.0,>=10.0.0