Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
-
|
2 |
-
Main application entry point for the Video Translator.
|
3 |
-
"""
|
4 |
import os
|
5 |
import tempfile
|
6 |
import shutil
|
@@ -22,15 +20,6 @@ logger = get_logger(__name__)
|
|
22 |
def process_video(video_file, source_lang, target_langs, progress=gr.Progress()):
|
23 |
"""
|
24 |
Process video file and generate translated versions.
|
25 |
-
|
26 |
-
Args:
|
27 |
-
video_file (str): Path to the uploaded video file
|
28 |
-
source_lang (str): Source language name
|
29 |
-
target_langs (list): List of target language names
|
30 |
-
progress (gr.Progress): Gradio progress tracker
|
31 |
-
|
32 |
-
Returns:
|
33 |
-
list: List of paths to translated videos
|
34 |
"""
|
35 |
try:
|
36 |
# Convert language names to codes
|
@@ -99,17 +88,27 @@ def process_video(video_file, source_lang, target_langs, progress=gr.Progress())
|
|
99 |
def create_app():
|
100 |
"""
|
101 |
Create and configure the Gradio application.
|
102 |
-
|
103 |
-
Returns:
|
104 |
-
gr.Blocks: Configured Gradio application
|
105 |
"""
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
gr.Markdown("# LinguaStream➿")
|
108 |
gr.Markdown("A Multilingual Audio and Video dubbing tool with supported subtitles.")
|
109 |
|
110 |
with gr.Row():
|
111 |
with gr.Column(scale=1):
|
112 |
video_input = gr.Video(label="Upload Video")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
source_lang = gr.Dropdown(
|
114 |
choices=sorted(list(LANGUAGES.keys())),
|
115 |
value="English",
|
@@ -136,6 +135,19 @@ def create_app():
|
|
136 |
outputs=output_gallery
|
137 |
)
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
gr.Markdown("""
|
140 |
## How it works
|
141 |
|
@@ -153,11 +165,12 @@ def create_app():
|
|
153 |
- Embedded subtitles
|
154 |
""")
|
155 |
|
156 |
-
return
|
157 |
|
158 |
if __name__ == "__main__":
|
159 |
-
|
160 |
-
|
|
|
161 |
|
162 |
-
|
163 |
-
|
|
|
1 |
+
|
|
|
|
|
2 |
import os
|
3 |
import tempfile
|
4 |
import shutil
|
|
|
20 |
def process_video(video_file, source_lang, target_langs, progress=gr.Progress()):
|
21 |
"""
|
22 |
Process video file and generate translated versions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"""
|
24 |
try:
|
25 |
# Convert language names to codes
|
|
|
88 |
def create_app():
|
89 |
"""
|
90 |
Create and configure the Gradio application.
|
|
|
|
|
|
|
91 |
"""
|
92 |
+
# Get path to sample video
|
93 |
+
sample_video_path = str(Path(__file__).parent / "samples" / "test_video.mp4")
|
94 |
+
sample_exists = Path(sample_video_path).exists()
|
95 |
+
|
96 |
+
with gr.Blocks(title="Video Translator") as app:
|
97 |
gr.Markdown("# LinguaStream➿")
|
98 |
gr.Markdown("A Multilingual Audio and Video dubbing tool with supported subtitles.")
|
99 |
|
100 |
with gr.Row():
|
101 |
with gr.Column(scale=1):
|
102 |
video_input = gr.Video(label="Upload Video")
|
103 |
+
|
104 |
+
# Sample video button
|
105 |
+
if sample_exists:
|
106 |
+
with gr.Row():
|
107 |
+
sample_btn = gr.Button("Load Sample Video", variant="secondary")
|
108 |
+
@sample_btn.click(inputs=[], outputs=[video_input])
|
109 |
+
def load_sample():
|
110 |
+
return sample_video_path
|
111 |
+
|
112 |
source_lang = gr.Dropdown(
|
113 |
choices=sorted(list(LANGUAGES.keys())),
|
114 |
value="English",
|
|
|
135 |
outputs=output_gallery
|
136 |
)
|
137 |
|
138 |
+
# Add sample download instructions if sample doesn't exist
|
139 |
+
if not sample_exists:
|
140 |
+
gr.Markdown("""
|
141 |
+
## Sample Video Not Found
|
142 |
+
To test the app, please upload your own video or place a test video at:
|
143 |
+
`samples/test_video.mp4`
|
144 |
+
""")
|
145 |
+
else:
|
146 |
+
gr.Markdown(f"""
|
147 |
+
## Sample Video Loaded
|
148 |
+
Click "Load Sample Video" to test with a {get_video_duration(sample_video_path):.1f}-second sample.
|
149 |
+
""")
|
150 |
+
|
151 |
gr.Markdown("""
|
152 |
## How it works
|
153 |
|
|
|
165 |
- Embedded subtitles
|
166 |
""")
|
167 |
|
168 |
+
return app
|
169 |
|
170 |
if __name__ == "__main__":
|
171 |
+
# Create output directories if they don't exist
|
172 |
+
(OUTPUT_DIR / "temp").mkdir(parents=True, exist_ok=True)
|
173 |
+
(OUTPUT_DIR / "logs").mkdir(parents=True, exist_ok=True)
|
174 |
|
175 |
+
app = create_app()
|
176 |
+
app.launch()
|