| from fastapi import FastAPI |
| import gradio as gr |
| import requests |
| import os |
|
|
| app = FastAPI() |
|
|
| def display_video(video_url, sas_token): |
| try: |
| full_url = f"{video_url}?{sas_token}" |
| temp_file = "temp_video.mp4" |
| response = requests.get(full_url, timeout=10) |
| if response.status_code == 200: |
| with open(temp_file, "wb") as f: |
| f.write(response.content) |
| return temp_file, "Video loaded successfully" |
| return None, f"Failed to fetch video: {response.status_code}" |
| except Exception as e: |
| return None, f"Error: {str(e)}" |
|
|
| @app.post("/process_video") |
| async def process_video(data: dict): |
| video_url = data.get("video_url") |
| sas_token = data.get("sas_token") |
| if not video_url or not sas_token: |
| return {"error": "Missing video_url or sas_token"} |
| video_path, message = display_video(video_url, sas_token) |
| return {"status": "success" if video_path else "error", "message": message} |
|
|
| def gradio_interface(video_url, sas_token): |
| video_path, message = display_video(video_url, sas_token) |
| return video_path, message |
|
|
| iface = gr.Interface( |
| fn=gradio_interface, |
| inputs=[ |
| gr.Textbox(label="Video URL"), |
| gr.Textbox(label="SAS Token") |
| ], |
| outputs=[ |
| gr.Video(label="Video"), |
| gr.Text(label="Status") |
| ], |
| title="PRISM Site Diary V3 Video Viewer", |
| description="Enter video URL and SAS token to view." |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch(server_name="0.0.0.0", server_port=7860) |