Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,9 @@ def process_video(video_path, min_silence_len=1000, silence_thresh=-40, max_work
|
|
65 |
"""
|
66 |
Remove segmentos silenciosos do vídeo com processamento otimizado.
|
67 |
"""
|
|
|
|
|
|
|
68 |
# Criar diretório temporário
|
69 |
temp_dir = tempfile.mkdtemp()
|
70 |
|
@@ -109,24 +112,33 @@ def process_video(video_path, min_silence_len=1000, silence_thresh=-40, max_work
|
|
109 |
|
110 |
return final_output
|
111 |
|
|
|
|
|
112 |
finally:
|
113 |
# Limpar arquivos temporários
|
114 |
shutil.rmtree(temp_dir)
|
115 |
|
116 |
-
def remove_silence(
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
try:
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
)
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
except Exception as e:
|
131 |
gr.Error(str(e))
|
132 |
return None
|
@@ -142,9 +154,11 @@ with gr.Blocks(title="Removedor de Silêncio de Vídeos") as app:
|
|
142 |
|
143 |
with gr.Row():
|
144 |
with gr.Column():
|
|
|
145 |
video_input = gr.Video(
|
146 |
-
label="
|
147 |
-
|
|
|
148 |
)
|
149 |
silence_duration = gr.Slider(
|
150 |
minimum=0.1,
|
@@ -161,15 +175,36 @@ with gr.Blocks(title="Removedor de Silêncio de Vídeos") as app:
|
|
161 |
label="Limite de Silêncio (dB)"
|
162 |
)
|
163 |
process_btn = gr.Button("Processar Vídeo")
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
165 |
with gr.Column():
|
|
|
|
|
166 |
video_output = gr.Video(label="Vídeo Processado")
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
process_btn.click(
|
169 |
fn=remove_silence,
|
170 |
-
inputs=[
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
)
|
173 |
|
174 |
if __name__ == "__main__":
|
175 |
-
app.launch()
|
|
|
65 |
"""
|
66 |
Remove segmentos silenciosos do vídeo com processamento otimizado.
|
67 |
"""
|
68 |
+
if not os.path.exists(video_path):
|
69 |
+
raise ValueError("Arquivo de vídeo não encontrado")
|
70 |
+
|
71 |
# Criar diretório temporário
|
72 |
temp_dir = tempfile.mkdtemp()
|
73 |
|
|
|
112 |
|
113 |
return final_output
|
114 |
|
115 |
+
except Exception as e:
|
116 |
+
raise Exception(f"Erro ao processar vídeo: {str(e)}")
|
117 |
finally:
|
118 |
# Limpar arquivos temporários
|
119 |
shutil.rmtree(temp_dir)
|
120 |
|
121 |
+
def remove_silence(video_input, silence_duration, silence_threshold):
|
122 |
+
"""
|
123 |
+
Função principal que processa o vídeo e retorna o caminho do vídeo processado
|
124 |
+
"""
|
125 |
try:
|
126 |
+
if video_input is None:
|
127 |
+
raise ValueError("Por favor, faça upload de um vídeo")
|
128 |
+
|
129 |
+
# Processar o vídeo
|
130 |
+
processed_video = process_video(
|
131 |
+
video_input,
|
132 |
+
min_silence_len=int(silence_duration * 1000),
|
133 |
+
silence_thresh=silence_threshold
|
134 |
+
)
|
135 |
+
|
136 |
+
# Retornar tanto o vídeo original quanto o processado
|
137 |
+
return {
|
138 |
+
video_output: processed_video,
|
139 |
+
video_input_display: video_input
|
140 |
+
}
|
141 |
+
|
142 |
except Exception as e:
|
143 |
gr.Error(str(e))
|
144 |
return None
|
|
|
154 |
|
155 |
with gr.Row():
|
156 |
with gr.Column():
|
157 |
+
# Input components
|
158 |
video_input = gr.Video(
|
159 |
+
label="Selecione ou Arraste o Vídeo",
|
160 |
+
format="mp4",
|
161 |
+
interactive=True
|
162 |
)
|
163 |
silence_duration = gr.Slider(
|
164 |
minimum=0.1,
|
|
|
175 |
label="Limite de Silêncio (dB)"
|
176 |
)
|
177 |
process_btn = gr.Button("Processar Vídeo")
|
178 |
+
|
179 |
+
with gr.Row():
|
180 |
+
with gr.Column():
|
181 |
+
# Display do vídeo original
|
182 |
+
gr.Markdown("### Vídeo Original")
|
183 |
+
video_input_display = gr.Video(label="Vídeo Original")
|
184 |
with gr.Column():
|
185 |
+
# Display do vídeo processado
|
186 |
+
gr.Markdown("### Vídeo Processado (Sem Silêncio)")
|
187 |
video_output = gr.Video(label="Vídeo Processado")
|
188 |
|
189 |
+
# Event handlers
|
190 |
+
video_input.change(
|
191 |
+
fn=lambda x: x,
|
192 |
+
inputs=[video_input],
|
193 |
+
outputs=[video_input_display]
|
194 |
+
)
|
195 |
+
|
196 |
process_btn.click(
|
197 |
fn=remove_silence,
|
198 |
+
inputs=[
|
199 |
+
video_input,
|
200 |
+
silence_duration,
|
201 |
+
silence_threshold
|
202 |
+
],
|
203 |
+
outputs=[
|
204 |
+
video_output,
|
205 |
+
video_input_display
|
206 |
+
]
|
207 |
)
|
208 |
|
209 |
if __name__ == "__main__":
|
210 |
+
app.launch(show_error=True)
|