Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ This app helps you:
|
|
18 |
- Process videos with multiple speakers.
|
19 |
""")
|
20 |
|
21 |
-
#
|
22 |
if "video_path" not in st.session_state:
|
23 |
st.session_state.video_path = None
|
24 |
if "transcription" not in st.session_state:
|
@@ -26,26 +26,18 @@ if "transcription" not in st.session_state:
|
|
26 |
|
27 |
# Upload Video Section
|
28 |
st.header("Upload Your Video")
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
with col1:
|
33 |
-
local_upload_btn = st.button("π Upload Local Video")
|
34 |
-
with col2:
|
35 |
-
youtube_upload_btn = st.button("πΊ Upload YouTube Video")
|
36 |
-
|
37 |
-
# Upload Local File
|
38 |
-
if local_upload_btn:
|
39 |
-
video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"], key="local-upload")
|
40 |
if video_file:
|
41 |
with open("uploaded_video.mp4", "wb") as f:
|
42 |
f.write(video_file.read())
|
43 |
st.session_state.video_path = "uploaded_video.mp4"
|
44 |
st.success("Video uploaded successfully!")
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
youtube_url = st.text_input("Enter YouTube URL", key="youtube-upload")
|
49 |
if youtube_url:
|
50 |
try:
|
51 |
os.system(f"yt-dlp -o video.mp4 {youtube_url}")
|
@@ -54,14 +46,13 @@ if youtube_upload_btn:
|
|
54 |
except Exception as e:
|
55 |
st.error(f"Error downloading video: {str(e)}")
|
56 |
|
57 |
-
#
|
58 |
if st.session_state.video_path:
|
59 |
-
st.header("Process
|
60 |
st.video(st.session_state.video_path)
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
if process_btn:
|
66 |
def extract_audio(video_path):
|
67 |
try:
|
@@ -70,11 +61,9 @@ if st.session_state.video_path:
|
|
70 |
st.success("Audio extracted successfully!")
|
71 |
return "extracted_audio.mp3"
|
72 |
except Exception as e:
|
73 |
-
st.error(f"Error
|
74 |
return None
|
75 |
|
76 |
-
audio_path = extract_audio(st.session_state.video_path)
|
77 |
-
|
78 |
def transcribe_audio(audio_path):
|
79 |
try:
|
80 |
model = whisper.load_model("base")
|
@@ -86,10 +75,11 @@ if st.session_state.video_path:
|
|
86 |
st.error(f"Error in transcription: {str(e)}")
|
87 |
return None
|
88 |
|
|
|
89 |
if audio_path:
|
90 |
st.session_state.transcription = transcribe_audio(audio_path)
|
91 |
|
92 |
-
#
|
93 |
if st.session_state.transcription:
|
94 |
st.header("Results")
|
95 |
|
@@ -126,5 +116,6 @@ if st.session_state.transcription:
|
|
126 |
if summary and translate_btn:
|
127 |
target_language = st.selectbox("Select Translation Language", ["es", "fr", "de", "zh"], key="lang-select")
|
128 |
translated_summary = translate_text(summary, tgt_lang=target_language)
|
|
|
129 |
else:
|
130 |
st.info("Please upload a video to start the process.")
|
|
|
18 |
- Process videos with multiple speakers.
|
19 |
""")
|
20 |
|
21 |
+
# Initialize session state
|
22 |
if "video_path" not in st.session_state:
|
23 |
st.session_state.video_path = None
|
24 |
if "transcription" not in st.session_state:
|
|
|
26 |
|
27 |
# Upload Video Section
|
28 |
st.header("Upload Your Video")
|
29 |
+
upload_option = st.radio("Choose upload method:", ["π Local File", "πΊ YouTube URL"])
|
30 |
|
31 |
+
if upload_option == "π Local File":
|
32 |
+
video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
if video_file:
|
34 |
with open("uploaded_video.mp4", "wb") as f:
|
35 |
f.write(video_file.read())
|
36 |
st.session_state.video_path = "uploaded_video.mp4"
|
37 |
st.success("Video uploaded successfully!")
|
38 |
|
39 |
+
elif upload_option == "πΊ YouTube URL":
|
40 |
+
youtube_url = st.text_input("Enter YouTube URL")
|
|
|
41 |
if youtube_url:
|
42 |
try:
|
43 |
os.system(f"yt-dlp -o video.mp4 {youtube_url}")
|
|
|
46 |
except Exception as e:
|
47 |
st.error(f"Error downloading video: {str(e)}")
|
48 |
|
49 |
+
# Display video
|
50 |
if st.session_state.video_path:
|
51 |
+
st.header("Preview & Process Video")
|
52 |
st.video(st.session_state.video_path)
|
53 |
+
|
54 |
+
process_btn = st.button("π Process Video", key="process-video", use_container_width=True)
|
55 |
+
|
|
|
56 |
if process_btn:
|
57 |
def extract_audio(video_path):
|
58 |
try:
|
|
|
61 |
st.success("Audio extracted successfully!")
|
62 |
return "extracted_audio.mp3"
|
63 |
except Exception as e:
|
64 |
+
st.error(f"Error extracting audio: {str(e)}")
|
65 |
return None
|
66 |
|
|
|
|
|
67 |
def transcribe_audio(audio_path):
|
68 |
try:
|
69 |
model = whisper.load_model("base")
|
|
|
75 |
st.error(f"Error in transcription: {str(e)}")
|
76 |
return None
|
77 |
|
78 |
+
audio_path = extract_audio(st.session_state.video_path)
|
79 |
if audio_path:
|
80 |
st.session_state.transcription = transcribe_audio(audio_path)
|
81 |
|
82 |
+
# Summarization & Translation
|
83 |
if st.session_state.transcription:
|
84 |
st.header("Results")
|
85 |
|
|
|
116 |
if summary and translate_btn:
|
117 |
target_language = st.selectbox("Select Translation Language", ["es", "fr", "de", "zh"], key="lang-select")
|
118 |
translated_summary = translate_text(summary, tgt_lang=target_language)
|
119 |
+
|
120 |
else:
|
121 |
st.info("Please upload a video to start the process.")
|