syedfaisalabrar commited on
Commit
853d801
·
verified ·
1 Parent(s): 808dc63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -1,22 +1,30 @@
1
  import gradio as gr
 
 
 
2
 
3
- # Define the function to be used in the interface
4
- def greet(name):
5
- return "Hello " + name + "!!"
6
 
7
- # Create a description for the interface
 
 
 
 
 
 
8
  description = """
9
- Welcome to the Gradio interface! This simple app detects the mouse feet observing from below.
10
- You can try it out by uploading an image!
11
  """
12
 
13
- # Define the interface with inputs and outputs
14
  demo = gr.Interface(
15
- fn=greet,
16
  inputs=gr.Image(label="Upload an Image"),
17
- outputs=gr.Textbox(label="Greeting"),
18
  live=True,
19
- title="Greeting App",
20
  description=description
21
  )
22
 
 
1
  import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ import numpy as np
5
 
6
+ # Load your YOLO model (Make sure the model is in PyTorch format)
7
+ model = torch.hub.load('ultralytics/yolov5', 'yolov8', pretrained=True) # Replace with YOLOv8
 
8
 
9
+ # Define the prediction function for YOLO model
10
+ def predict(image):
11
+ image = Image.fromarray(np.array(image)) # Convert image to PIL format
12
+ results = model(image) # Get predictions from YOLO model
13
+ return f"Predicted class: {results.names[results.pred[0, -1].item()]}" # Extract class name
14
+
15
+ # Define the description and interface
16
  description = """
17
+ Welcome to the Gradio interface! This simple app detects mouse feet observing from below.
18
+ Upload an image to see the prediction results!
19
  """
20
 
21
+ # Create the Gradio interface
22
  demo = gr.Interface(
23
+ fn=predict,
24
  inputs=gr.Image(label="Upload an Image"),
25
+ outputs=gr.Textbox(label="Prediction Result"),
26
  live=True,
27
+ title="Mouse Feet Detection",
28
  description=description
29
  )
30