Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -201,34 +201,37 @@
|
|
| 201 |
# iface.launch()
|
| 202 |
|
| 203 |
import gradio as gr
|
| 204 |
-
import
|
| 205 |
-
from
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
#
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
#
|
| 221 |
-
#
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
iface = gr.Interface(fn=run_model, inputs="webcam", outputs=annotated_img)
|
| 234 |
-
iface.launch()
|
|
|
|
| 201 |
# iface.launch()
|
| 202 |
|
| 203 |
import gradio as gr
|
| 204 |
+
import torch
|
| 205 |
+
from PIL import Image
|
| 206 |
+
import torchvision.transforms as T
|
| 207 |
+
|
| 208 |
+
# Load your model
|
| 209 |
+
model = torch.load("model.pt")
|
| 210 |
+
model.eval()
|
| 211 |
+
|
| 212 |
+
# Define preprocessing
|
| 213 |
+
transform = T.Compose([
|
| 214 |
+
T.Resize((224, 224)), # Adjust to your model's input size
|
| 215 |
+
T.ToTensor(),
|
| 216 |
+
])
|
| 217 |
+
|
| 218 |
+
def predict(image):
|
| 219 |
+
# Preprocess the image
|
| 220 |
+
img_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
| 221 |
|
| 222 |
+
# Make prediction
|
| 223 |
+
with torch.no_grad():
|
| 224 |
+
output = model(img_tensor)
|
| 225 |
+
|
| 226 |
+
# Process output (adjust based on your model's format)
|
| 227 |
+
return output.tolist() # or post-process the results as needed
|
| 228 |
+
|
| 229 |
+
# Gradio interface
|
| 230 |
+
demo = gr.Interface(
|
| 231 |
+
fn=predict,
|
| 232 |
+
inputs=gr.Image(type="pil"), # Accepts image input
|
| 233 |
+
outputs="json" # Customize based on your output format
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
if __name__ == "__main__":
|
| 237 |
+
demo.launch()
|
|
|
|
|
|
|
|
|