-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (38 loc) · 1.75 KB
/
app.py
File metadata and controls
42 lines (38 loc) · 1.75 KB
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
import streamlit as st
import requests, os
BACKEND_URL = "http://localhost:8000" # Change if backend runs elsewhere
st.title("Video Q&A RAG System")
uploaded_file = st.file_uploader("Upload a video", type=["mp4", "mov"])
if uploaded_file:
try:
# send to backend as multipart file correctly
files = {"file": (uploaded_file.name, uploaded_file.getvalue(), uploaded_file.type)}
with st.spinner("Uploading and processing (this can take a few minutes on CPU)..."):
# increase timeout for slow CPU transcription/indexing
res = requests.post(f"{BACKEND_URL}/upload", files=files, timeout=600)
if res.status_code == 200:
st.success("Video uploaded and processed!")
else:
st.error(f"Backend error: {res.text}")
except Exception as e:
st.error(f"File upload error: {e}")
query = st.text_input("Ask a question about the video:")
if st.button("Submit") and query:
try:
res = requests.get(f"{BACKEND_URL}/query", params={"q": query}, timeout=60)
if res.status_code == 200:
data = res.json()
st.write(data.get("response"))
frames = data.get("frames", [])
# show frames inline if returned
if frames:
# frames are local paths on server; Streamlit is local so it can open them
for p in frames:
if os.path.exists(p):
st.image(p, use_column_width=True)
else:
st.write(f"Frame not found: {p}")
else:
st.error(f"Backend error: {res.text}")
except Exception as e:
st.error(f"Query error: {e}")