Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,31 +9,6 @@ import yt_dlp as youtube_dl
|
|
9 |
# App Configuration
|
10 |
st.set_page_config(page_title="Video-to-Text Summarization", layout="wide")
|
11 |
|
12 |
-
# Navbar-like Section
|
13 |
-
st.markdown("""
|
14 |
-
<style>
|
15 |
-
.nav-links {
|
16 |
-
display: flex;
|
17 |
-
justify-content: center;
|
18 |
-
gap: 20px;
|
19 |
-
}
|
20 |
-
.nav-links a {
|
21 |
-
text-decoration: none;
|
22 |
-
padding: 10px 20px;
|
23 |
-
background: #4CAF50;
|
24 |
-
color: white;
|
25 |
-
border-radius: 5px;
|
26 |
-
}
|
27 |
-
</style>
|
28 |
-
""", unsafe_allow_html=True)
|
29 |
-
|
30 |
-
st.markdown("""
|
31 |
-
<div class='nav-links'>
|
32 |
-
<a href='#local-upload'>Upload Local Video</a>
|
33 |
-
<a href='#youtube-upload'>Upload YouTube Video</a>
|
34 |
-
</div>
|
35 |
-
""", unsafe_allow_html=True)
|
36 |
-
|
37 |
# Header
|
38 |
st.title("π₯ Smart Video-to-Text Summarization App")
|
39 |
st.markdown("""
|
@@ -50,10 +25,15 @@ if "video_path" not in st.session_state:
|
|
50 |
# Upload Video Section
|
51 |
st.header("Upload Your Video")
|
52 |
|
|
|
53 |
col1, col2 = st.columns(2)
|
54 |
-
|
55 |
with col1:
|
56 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
57 |
video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"], key="local-upload")
|
58 |
if video_file:
|
59 |
with open("uploaded_video.mp4", "wb") as f:
|
@@ -61,8 +41,8 @@ with col1:
|
|
61 |
st.session_state.video_path = "uploaded_video.mp4"
|
62 |
st.success("Video uploaded successfully!")
|
63 |
|
64 |
-
|
65 |
-
|
66 |
youtube_url = st.text_input("Enter YouTube URL", key="youtube-upload")
|
67 |
if youtube_url:
|
68 |
try:
|
@@ -77,35 +57,41 @@ if st.session_state.video_path:
|
|
77 |
st.header("Process Your Video")
|
78 |
st.write(f"Processing {st.session_state.video_path}...")
|
79 |
|
80 |
-
|
81 |
-
try:
|
82 |
-
audio = AudioSegment.from_file(video_path)
|
83 |
-
audio.export("extracted_audio.mp3", format="mp3")
|
84 |
-
st.success("Audio extracted successfully!")
|
85 |
-
return "extracted_audio.mp3"
|
86 |
-
except Exception as e:
|
87 |
-
st.error(f"Error in extracting audio: {str(e)}")
|
88 |
-
return None
|
89 |
-
|
90 |
-
audio_path = extract_audio(st.session_state.video_path)
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# Summarize and Translate Section
|
106 |
if 'transcription' in locals():
|
107 |
st.header("Results")
|
108 |
|
|
|
|
|
|
|
109 |
def summarize_text(text):
|
110 |
try:
|
111 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
@@ -116,7 +102,9 @@ if 'transcription' in locals():
|
|
116 |
st.error(f"Error in summarization: {str(e)}")
|
117 |
return None
|
118 |
|
119 |
-
summary =
|
|
|
|
|
120 |
|
121 |
def translate_text(text, src_lang="en", tgt_lang="es"):
|
122 |
try:
|
@@ -131,9 +119,8 @@ if 'transcription' in locals():
|
|
131 |
st.error(f"Error in translation: {str(e)}")
|
132 |
return None
|
133 |
|
134 |
-
|
135 |
-
|
136 |
translated_summary = translate_text(summary, tgt_lang=target_language)
|
137 |
-
|
138 |
else:
|
139 |
st.info("Please upload a video to start the process.")
|
|
|
9 |
# App Configuration
|
10 |
st.set_page_config(page_title="Video-to-Text Summarization", layout="wide")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Header
|
13 |
st.title("π₯ Smart Video-to-Text Summarization App")
|
14 |
st.markdown("""
|
|
|
25 |
# Upload Video Section
|
26 |
st.header("Upload Your Video")
|
27 |
|
28 |
+
# Buttons for navigation
|
29 |
col1, col2 = st.columns(2)
|
|
|
30 |
with col1:
|
31 |
+
local_upload_btn = st.button("π Upload Local Video")
|
32 |
+
with col2:
|
33 |
+
youtube_upload_btn = st.button("πΊ Upload YouTube Video")
|
34 |
+
|
35 |
+
# Upload Local File
|
36 |
+
if local_upload_btn:
|
37 |
video_file = st.file_uploader("Upload your video file", type=["mp4", "mkv", "avi"], key="local-upload")
|
38 |
if video_file:
|
39 |
with open("uploaded_video.mp4", "wb") as f:
|
|
|
41 |
st.session_state.video_path = "uploaded_video.mp4"
|
42 |
st.success("Video uploaded successfully!")
|
43 |
|
44 |
+
# Download Video from YouTube
|
45 |
+
if youtube_upload_btn:
|
46 |
youtube_url = st.text_input("Enter YouTube URL", key="youtube-upload")
|
47 |
if youtube_url:
|
48 |
try:
|
|
|
57 |
st.header("Process Your Video")
|
58 |
st.write(f"Processing {st.session_state.video_path}...")
|
59 |
|
60 |
+
process_btn = st.button("π Start Processing")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
if process_btn:
|
63 |
+
def extract_audio(video_path):
|
64 |
+
try:
|
65 |
+
audio = AudioSegment.from_file(video_path)
|
66 |
+
audio.export("extracted_audio.mp3", format="mp3")
|
67 |
+
st.success("Audio extracted successfully!")
|
68 |
+
return "extracted_audio.mp3"
|
69 |
+
except Exception as e:
|
70 |
+
st.error(f"Error in extracting audio: {str(e)}")
|
71 |
+
return None
|
72 |
+
|
73 |
+
audio_path = extract_audio(st.session_state.video_path)
|
74 |
+
|
75 |
+
def transcribe_audio(audio_path):
|
76 |
+
try:
|
77 |
+
model = whisper.load_model("base")
|
78 |
+
result = model.transcribe(audio_path)
|
79 |
+
st.text_area("Transcription", result['text'], height=200)
|
80 |
+
return result['text']
|
81 |
+
except Exception as e:
|
82 |
+
st.error(f"Error in transcription: {str(e)}")
|
83 |
+
return None
|
84 |
+
|
85 |
+
if audio_path:
|
86 |
+
transcription = transcribe_audio(audio_path)
|
87 |
|
88 |
# Summarize and Translate Section
|
89 |
if 'transcription' in locals():
|
90 |
st.header("Results")
|
91 |
|
92 |
+
summarize_btn = st.button("π Summarize Text")
|
93 |
+
translate_btn = st.button("π Translate Summary")
|
94 |
+
|
95 |
def summarize_text(text):
|
96 |
try:
|
97 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
102 |
st.error(f"Error in summarization: {str(e)}")
|
103 |
return None
|
104 |
|
105 |
+
summary = None
|
106 |
+
if summarize_btn:
|
107 |
+
summary = summarize_text(transcription)
|
108 |
|
109 |
def translate_text(text, src_lang="en", tgt_lang="es"):
|
110 |
try:
|
|
|
119 |
st.error(f"Error in translation: {str(e)}")
|
120 |
return None
|
121 |
|
122 |
+
if summary and translate_btn:
|
123 |
+
target_language = st.selectbox("Select Translation Language", ["es", "fr", "de", "zh"], key="lang-select")
|
124 |
translated_summary = translate_text(summary, tgt_lang=target_language)
|
|
|
125 |
else:
|
126 |
st.info("Please upload a video to start the process.")
|