BD_HAR_25 / app.py
bd04's picture
update app.py
c9ab9a6
import gradio as gr
import os
from inference import predict_activity
# Configure these paths
DATASET = "ucf11" # or 'ucf50'
MODEL_PATH = "models/ucf11_lstm_model.pt" # update if different
def predict_from_file(video_file):
# video_file is a path returned by Gradio when uploading
if video_file is None:
return "No file uploaded"
try:
cls_idx, label = predict_activity(DATASET, video_file, MODEL_PATH)
return f"Predicted: {cls_idx}{label}"
except Exception as e:
return f"Error: {e}"
with gr.Blocks() as demo:
gr.Markdown("# Human Activity Recognition - Video Inference")
with gr.Row():
video_in = gr.Video(label="Upload video")
out = gr.Textbox(label="Prediction")
btn = gr.Button("Predict")
btn.click(fn=predict_from_file, inputs=[video_in], outputs=[out])
if __name__ == "__main__":
# On Hugging Face Spaces, running `python app.py` should start Gradio
demo.launch(server_name="0.0.0.0", server_port=7860)