Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -141,37 +141,41 @@
|
|
141 |
# gradio_app.launch(debug=True)
|
142 |
|
143 |
# make sure you have the following dependencies
|
|
|
144 |
import torch
|
145 |
-
|
146 |
-
from
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
141 |
# gradio_app.launch(debug=True)
|
142 |
|
143 |
# make sure you have the following dependencies
|
144 |
+
import gradio as gr
|
145 |
import torch
|
146 |
+
from torchvision import transforms
|
147 |
+
from PIL import Image
|
148 |
+
|
149 |
+
# Load the YOLOv9 model
|
150 |
+
model_path = "best.pt" # Replace with the path to your YOLOv9 model
|
151 |
+
model = torch.load(model_path)
|
152 |
+
|
153 |
+
# Define preprocessing transforms
|
154 |
+
preprocess = transforms.Compose([
|
155 |
+
transforms.Resize((640, 640)), # Resize image to model input size
|
156 |
+
transforms.ToTensor(), # Convert image to tensor
|
157 |
+
])
|
158 |
+
|
159 |
+
# Define a function to perform inference
|
160 |
+
def detect_void(image):
|
161 |
+
# Preprocess the input image
|
162 |
+
image = Image.fromarray(image)
|
163 |
+
image = preprocess(image).unsqueeze(0) # Add batch dimension
|
164 |
+
|
165 |
+
# Perform inference
|
166 |
+
with torch.no_grad():
|
167 |
+
output = model(image)
|
168 |
+
|
169 |
+
# Post-process the output if needed
|
170 |
+
# For example, draw bounding boxes on the image
|
171 |
+
|
172 |
+
# Convert the image back to numpy array
|
173 |
+
# and return the result
|
174 |
+
return output.squeeze().numpy()
|
175 |
+
|
176 |
+
# Define Gradio interface components
|
177 |
+
input_image = gr.inputs.Image(shape=(640, 640), label="Input Image")
|
178 |
+
output_image = gr.outputs.Image(label="Output Image")
|
179 |
+
|
180 |
+
# Create Gradio interface
|
181 |
+
gr.Interface(fn=detect_void, inputs=input_image, outputs=output_image, title="Void Detection App").launch()
|