Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from model import CNNLSTMClassifier
|
| 4 |
+
from utils import extract_frames
|
| 5 |
+
|
| 6 |
+
model = CNNLSTMClassifier()
|
| 7 |
+
model.load_state_dict(torch.load("lbw_classifier.pt", map_location='cpu'))
|
| 8 |
+
model.eval()
|
| 9 |
+
|
| 10 |
+
classes = ["Not LBW", "LBW"]
|
| 11 |
+
|
| 12 |
+
def predict(video):
|
| 13 |
+
frames = extract_frames(video)
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(frames)
|
| 16 |
+
pred = torch.argmax(output, dim=1).item()
|
| 17 |
+
prob = torch.softmax(output, dim=1)[0][pred].item()
|
| 18 |
+
return f"Prediction: {classes[pred]} (Confidence: {prob:.2%})"
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=predict,
|
| 22 |
+
inputs=gr.Video(type="filepath"),
|
| 23 |
+
outputs=gr.Text(),
|
| 24 |
+
title="Smart LBW Classifier",
|
| 25 |
+
description="Upload a cricket video. The AI model will predict whether it's an LBW or not."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
iface.launch()
|