sparsh007 commited on
Commit
5723ab2
·
verified ·
1 Parent(s): 023eddb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import gradio as gr
3
+ import requests
4
+ import os
5
+
6
+ app = FastAPI()
7
+
8
+ def display_video(video_url, sas_token):
9
+ try:
10
+ full_url = f"{video_url}?{sas_token}"
11
+ temp_file = "temp_video.mp4"
12
+ response = requests.get(full_url, timeout=10)
13
+ if response.status_code == 200:
14
+ with open(temp_file, "wb") as f:
15
+ f.write(response.content)
16
+ return temp_file, "Video loaded successfully"
17
+ return None, f"Failed to fetch video: {response.status_code}"
18
+ except Exception as e:
19
+ return None, f"Error: {str(e)}"
20
+
21
+ @app.post("/process_video")
22
+ async def process_video(data: dict):
23
+ video_url = data.get("video_url")
24
+ sas_token = data.get("sas_token")
25
+ if not video_url or not sas_token:
26
+ return {"error": "Missing video_url or sas_token"}
27
+ video_path, message = display_video(video_url, sas_token)
28
+ return {"status": "success" if video_path else "error", "message": message}
29
+
30
+ def gradio_interface(video_url, sas_token):
31
+ video_path, message = display_video(video_url, sas_token)
32
+ return video_path, message
33
+
34
+ iface = gr.Interface(
35
+ fn=gradio_interface,
36
+ inputs=[
37
+ gr.Textbox(label="Video URL"),
38
+ gr.Textbox(label="SAS Token")
39
+ ],
40
+ outputs=[
41
+ gr.Video(label="Video"),
42
+ gr.Text(label="Status")
43
+ ],
44
+ title="PRISM Site Diary V3 Video Viewer",
45
+ description="Enter video URL and SAS token to view."
46
+ )
47
+
48
+ if __name__ == "__main__":
49
+ iface.launch(server_name="0.0.0.0", server_port=7860)