Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import os | |
| # API endpoint - using environment variable with fallback | |
| API_URL = os.getenv("API_URL", "http://34.58.134.224:8000/process_video") | |
| def process_video(video_path, prompt): | |
| try: | |
| # Prepare the files and data | |
| files = { | |
| 'video': ('video.mp4', open(video_path, 'rb'), 'video/mp4') | |
| } | |
| data = { | |
| 'prompt': prompt | |
| } | |
| # Make the API request | |
| response = requests.post(API_URL, files=files, data=data) | |
| response.raise_for_status() # Raise an exception for bad status codes | |
| # Return the response | |
| return response.json()['response'] | |
| except requests.exceptions.ConnectionError: | |
| return "Error: Could not connect to the API server. Please try again later." | |
| except requests.exceptions.RequestException as e: | |
| return f"Error: API request failed - {str(e)}" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=process_video, | |
| inputs=[ | |
| gr.Video(label="Upload Video"), | |
| gr.Textbox(label="Enter your prompt", placeholder="What is going on in this video?") | |
| ], | |
| outputs=gr.Textbox(label="Model Response"), | |
| title="Video Analysis with VLM", | |
| description="Upload a video and ask questions about it. The model will analyze the video and respond to your prompt." | |
| ) | |
| # Launch the app for Hugging Face Spaces | |
| iface.launch() |