| import gradio as gr |
| import os |
| from inference import predict_activity |
|
|
| |
| DATASET = "ucf11" |
| MODEL_PATH = "models/ucf11_lstm_model.pt" |
|
|
|
|
| def predict_from_file(video_file): |
| |
| 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__": |
| |
| demo.launch(server_name="0.0.0.0", server_port=7860) |
|
|