Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,15 +48,20 @@ def translate_text(text, tgt_lang="es"):
|
|
48 |
return str(e)
|
49 |
|
50 |
def process_video(video_file, youtube_url, video_source):
|
|
|
|
|
|
|
51 |
if video_source == "Local Video" and video_file:
|
52 |
video_path = video_file.name
|
53 |
elif video_source == "YouTube" and youtube_url:
|
54 |
video_path = download_youtube_video(youtube_url)
|
55 |
else:
|
56 |
-
return "No valid input provided."
|
57 |
|
|
|
58 |
audio_path = extract_audio(video_path)
|
59 |
transcription = transcribe_audio(audio_path)
|
|
|
60 |
return transcription, video_path
|
61 |
|
62 |
def summarize_and_translate(text, lang):
|
@@ -86,20 +91,42 @@ with gr.Blocks(css="""
|
|
86 |
-webkit-background-clip: text;
|
87 |
color: transparent;
|
88 |
}
|
|
|
|
|
|
|
|
|
89 |
""") as app:
|
90 |
gr.Markdown("<h1 class='gradient-font'>🎥 Smart Video-to-Text Summarization App</h1>")
|
91 |
|
92 |
with gr.Row():
|
93 |
video_source = gr.Radio(["Local Video", "YouTube"], label="Choose Video Source", value="Local Video")
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
video_display = gr.Video(label="Processed Video", visible=False)
|
98 |
-
|
99 |
process_button = gr.Button("🚀 Process Video", elem_classes=["btn-blue"])
|
100 |
transcription_output = gr.Textbox(label="Transcription", interactive=False)
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
summarize_button = gr.Button("📝 Summarize Text", elem_classes=["btn-blue"])
|
105 |
summary_output = gr.Textbox(label="Summary", interactive=False)
|
|
|
48 |
return str(e)
|
49 |
|
50 |
def process_video(video_file, youtube_url, video_source):
|
51 |
+
video_path = ""
|
52 |
+
|
53 |
+
# Handle Video Selection Based on Radio Button
|
54 |
if video_source == "Local Video" and video_file:
|
55 |
video_path = video_file.name
|
56 |
elif video_source == "YouTube" and youtube_url:
|
57 |
video_path = download_youtube_video(youtube_url)
|
58 |
else:
|
59 |
+
return "No valid input provided.", None
|
60 |
|
61 |
+
# Extract Audio and Transcribe
|
62 |
audio_path = extract_audio(video_path)
|
63 |
transcription = transcribe_audio(audio_path)
|
64 |
+
|
65 |
return transcription, video_path
|
66 |
|
67 |
def summarize_and_translate(text, lang):
|
|
|
91 |
-webkit-background-clip: text;
|
92 |
color: transparent;
|
93 |
}
|
94 |
+
.gradio-container {
|
95 |
+
background-color: black;
|
96 |
+
color: white;
|
97 |
+
}
|
98 |
""") as app:
|
99 |
gr.Markdown("<h1 class='gradient-font'>🎥 Smart Video-to-Text Summarization App</h1>")
|
100 |
|
101 |
with gr.Row():
|
102 |
video_source = gr.Radio(["Local Video", "YouTube"], label="Choose Video Source", value="Local Video")
|
103 |
+
|
104 |
+
with gr.Column(visible=True) as video_section:
|
105 |
+
# Display tabs based on radio selection
|
106 |
+
local_video_tab = gr.File(label="Upload Local Video File", type="filepath", visible=True)
|
107 |
+
youtube_video_tab = gr.Textbox(label="YouTube URL", visible=False)
|
108 |
+
|
109 |
+
def switch_tabs(source):
|
110 |
+
if source == "Local Video":
|
111 |
+
local_video_tab.visible = True
|
112 |
+
youtube_video_tab.visible = False
|
113 |
+
elif source == "YouTube":
|
114 |
+
local_video_tab.visible = False
|
115 |
+
youtube_video_tab.visible = True
|
116 |
+
|
117 |
+
video_source.change(switch_tabs, inputs=video_source)
|
118 |
+
|
119 |
video_display = gr.Video(label="Processed Video", visible=False)
|
120 |
+
|
121 |
process_button = gr.Button("🚀 Process Video", elem_classes=["btn-blue"])
|
122 |
transcription_output = gr.Textbox(label="Transcription", interactive=False)
|
123 |
|
124 |
+
# Show video and process it after selection
|
125 |
+
def display_video(video_path):
|
126 |
+
return video_path # Display the video selected/processed
|
127 |
+
|
128 |
+
process_button.click(process_video, inputs=[local_video_tab, youtube_video_tab, video_source], outputs=[transcription_output, video_display])
|
129 |
+
process_button.click(display_video, inputs=[video_display], outputs=video_display)
|
130 |
|
131 |
summarize_button = gr.Button("📝 Summarize Text", elem_classes=["btn-blue"])
|
132 |
summary_output = gr.Textbox(label="Summary", interactive=False)
|