userIdc2024 commited on
Commit
2727837
·
verified ·
1 Parent(s): 8ba42b4

Upload 2 files

Browse files
app_pages/video_hashid_generation.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tempfile
3
+ from generator_function.video_hashid_function import process_video_with_hash_info
4
+ # from database.operations import insert_video_hashid_result
5
+
6
+ def render_video_hashid(uid: str):
7
+ st.markdown("#### Change video hashid")
8
+
9
+ uploaded_file = st.file_uploader(
10
+ "Choose a video file",
11
+ type=['mp4', 'avi', 'mov', 'mkv', 'wmv', 'flv', 'webm'],
12
+ )
13
+
14
+ generate_clicked = st.button(
15
+ "Generate Augmented Video",
16
+ type="primary",
17
+ use_container_width=True,
18
+ disabled=uploaded_file is None
19
+ )
20
+
21
+ result = None
22
+
23
+ if uploaded_file is not None:
24
+ st.success(f"File uploaded: {uploaded_file.name} ({uploaded_file.size / 1024 / 1024:.1f} MB)")
25
+
26
+ col1, col2 = st.columns([1, 1])
27
+
28
+ with col1:
29
+ st.markdown("### Original Video")
30
+ st.video(uploaded_file)
31
+
32
+ with col2:
33
+ st.markdown("### Augmented Video")
34
+
35
+ if generate_clicked:
36
+ with st.spinner("Processing video..."):
37
+ with tempfile.NamedTemporaryFile(delete=False, suffix=f"_{uploaded_file.name}") as tmp_input:
38
+ tmp_input.write(uploaded_file.getvalue())
39
+ tmp_input_path = tmp_input.name
40
+
41
+ with tempfile.TemporaryDirectory() as tmp_dir:
42
+ result = process_video_with_hash_info(
43
+ input_path=tmp_input_path,
44
+ output_path=tmp_dir
45
+ )
46
+
47
+ if result:
48
+ st.video(result["output_r2_url"])
49
+ st.markdown(f"**Input Hash ID:** `{result['input_hashid']}`")
50
+ st.markdown(f"**Output Hash ID:** `{result['output_hashid']}`")
51
+
52
+ st.download_button(
53
+ "Download Augmented Video",
54
+ data=open(result["output_path"], "rb").read(),
55
+ file_name=result["output_name"],
56
+ mime="video/mp4",
57
+ use_container_width=True
58
+ )
59
+
60
+
61
+ # insert_video_hashid_result(
62
+ # video_name=uploaded_file.name,
63
+ # output_r2_url=result["output_r2_url"],
64
+ # output_hashid=result["output_hashid"],
65
+ # input_hashid=result["input_hashid"],
66
+ # thumbnail=result["thumbnail"],
67
+ # created_by=uid,
68
+ # )
app_pages/video_text_generation.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, tempfile, logging
2
+ import streamlit as st
3
+ from dotenv import load_dotenv
4
+ # from database.operations import insert_video_text_result
5
+ from helpers_function.helpers import get_video_thumbnail_base64
6
+ from generator_function.video_text_generator import extract_text_from_video
7
+
8
+ logging.basicConfig(level=logging.INFO)
9
+ logger = logging.getLogger(__name__)
10
+
11
+ load_dotenv()
12
+
13
+
14
+ def render_video_to_text(uid: str = None):
15
+ st.subheader("Video → Text")
16
+
17
+ category = st.text_input("Category")
18
+ uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])
19
+
20
+ if uploaded_file:
21
+ st.video(uploaded_file)
22
+
23
+ if st.button("Convert to Text", width="content"):
24
+ with st.spinner("Processing video..."):
25
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp:
26
+ tmp.write(uploaded_file.read())
27
+ tmp_path = tmp.name
28
+
29
+ result = extract_text_from_video(tmp_path)
30
+
31
+ if not result or "error" in result:
32
+ st.error(f"Error: {result.get('error', 'Unknown failure')}")
33
+ else:
34
+ st.success("Video processed successfully!")
35
+
36
+ # Display the extracted text
37
+ if result and "text_output" in result:
38
+ st.subheader("Extracted Text")
39
+ st.text_area("Result", result["text_output"], height=200)
40
+ else:
41
+ st.warning("Text extraction was successful, but no text was found in the output.")
42
+
43
+ st.session_state["video_to_text_result"] = result
44
+ st.session_state["video_name"] = uploaded_file.name
45
+ st.session_state["category"] = category
46
+ try:
47
+ st.session_state["thumbnail"] = get_video_thumbnail_base64(tmp_path) or ""
48
+ except Exception as e:
49
+ logger.warning(f"Thumbnail generation failed: {e}")
50
+ st.session_state["thumbnail"] = ""
51
+
52
+ os.remove(tmp_path)
53
+
54
+ # if st.button("Save to DB", width="content", key="sg_save"):
55
+ # try:
56
+ # insert_video_text_result(
57
+ # video_name=st.session_state.get("video_name", "unknown"),
58
+ # response=st.session_state.get("video_to_text_result", {}),
59
+ # thumbnail=st.session_state.get("thumbnail", ""),
60
+ # created_by=uid,
61
+ # category=st.session_state.get("category"),
62
+ # )
63
+ # st.success("Generated text saved to database ")
64
+ # except Exception as e:
65
+ # st.error(f"Failed to save generated text: {e}")