File size: 1,542 Bytes
5723ab2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)