Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,69 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import ffmpeg
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def generate_video(input_video, text_overlay):
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
input_path = "input_video.mp4"
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
output_path = "output_video.mp4"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
-
|
| 27 |
-
.
|
| 28 |
-
|
| 29 |
|
|
|
|
| 30 |
return output_path
|
| 31 |
|
| 32 |
-
# Antarmuka Gradio
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=generate_video,
|
| 35 |
inputs=[
|
| 36 |
-
gr.File(label="Upload Video"
|
| 37 |
gr.Textbox(lines=2, label="Text Overlay"),
|
| 38 |
],
|
| 39 |
-
outputs=gr.Video(label="Generated Video"),
|
| 40 |
title="Video Generator (Veo 3 Style)",
|
| 41 |
-
description="Upload a video
|
| 42 |
)
|
| 43 |
|
| 44 |
# Jalankan aplikasi
|
| 45 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import ffmpeg
|
| 3 |
import os
|
| 4 |
+
import logging
|
| 5 |
|
| 6 |
+
# Konfigurasi logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
# Fungsi untuk generate video
|
| 11 |
def generate_video(input_video, text_overlay):
|
| 12 |
+
logger.info("Starting video generation...")
|
| 13 |
+
|
| 14 |
+
# Simpan file input
|
| 15 |
input_path = "input_video.mp4"
|
| 16 |
+
try:
|
| 17 |
+
with open(input_path, "wb") as video_file:
|
| 18 |
+
video_file.write(input_video)
|
| 19 |
+
except Exception as e:
|
| 20 |
+
logger.error(f"Failed to save input video: {e}")
|
| 21 |
+
raise gr.Error("Failed to save input video. Please try again.")
|
| 22 |
+
|
| 23 |
+
# Cek apakah file input ada
|
| 24 |
+
if not os.path.exists(input_path):
|
| 25 |
+
logger.error("Input file not found.")
|
| 26 |
+
raise gr.Error("Input file not found. Please upload a valid video.")
|
| 27 |
|
| 28 |
+
# Path untuk output video
|
| 29 |
output_path = "output_video.mp4"
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
# Proses video dengan FFmpeg (tambahkan teks overlay)
|
| 33 |
+
(
|
| 34 |
+
ffmpeg
|
| 35 |
+
.input(input_path)
|
| 36 |
+
.drawtext(
|
| 37 |
+
text=text_overlay,
|
| 38 |
+
fontsize=24,
|
| 39 |
+
fontcolor='white',
|
| 40 |
+
x=(10),
|
| 41 |
+
y=(10),
|
| 42 |
+
box=1,
|
| 43 |
+
boxcolor='black@0.5'
|
| 44 |
+
)
|
| 45 |
+
.output(output_path)
|
| 46 |
+
.run(capture_stderr=True)
|
| 47 |
)
|
| 48 |
+
except ffmpeg.Error as e:
|
| 49 |
+
logger.error(f"FFmpeg error: {e.stderr.decode()}")
|
| 50 |
+
raise gr.Error("Failed to process video. Please check the input file and try again.")
|
| 51 |
|
| 52 |
+
logger.info("Video generated successfully.")
|
| 53 |
return output_path
|
| 54 |
|
| 55 |
+
# Antarmuka Gradio
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=generate_video,
|
| 58 |
inputs=[
|
| 59 |
+
gr.File(label="Upload Video", type="filepath"),
|
| 60 |
gr.Textbox(lines=2, label="Text Overlay"),
|
| 61 |
],
|
| 62 |
+
outputs=gr.Video(label="Generated Video"),
|
| 63 |
title="Video Generator (Veo 3 Style)",
|
| 64 |
+
description="Upload a video, add text overlay, and generate a new video.",
|
| 65 |
)
|
| 66 |
|
| 67 |
# Jalankan aplikasi
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
iface.launch()
|