Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,10 @@ import requests
|
|
| 7 |
import base64
|
| 8 |
import math
|
| 9 |
|
|
|
|
| 10 |
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
|
|
|
|
|
|
| 11 |
API_URL = "https://text.pollinations.ai/openai"
|
| 12 |
|
| 13 |
def convert_to_wav(audio_path):
|
|
@@ -52,8 +55,8 @@ def generate_slideshow_with_audio(images, audio_file, duration_per_image=3, y_po
|
|
| 52 |
segments_per_image = math.ceil(total_words / len(images))
|
| 53 |
texts = []
|
| 54 |
for i in range(len(images)):
|
| 55 |
-
start = i*segments_per_image
|
| 56 |
-
end = min((i+1)*segments_per_image, total_words)
|
| 57 |
texts.append(" ".join(words[start:end]))
|
| 58 |
else:
|
| 59 |
texts = [""] * len(images)
|
|
@@ -69,7 +72,8 @@ def generate_slideshow_with_audio(images, audio_file, duration_per_image=3, y_po
|
|
| 69 |
)
|
| 70 |
|
| 71 |
if text:
|
| 72 |
-
|
|
|
|
| 73 |
drawtext_filter = (
|
| 74 |
f",drawtext=text='{safe_text}':fontcolor=white:fontsize={font_size}:borderw=2:"
|
| 75 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
|
|
@@ -141,7 +145,10 @@ with gr.Blocks() as demo:
|
|
| 141 |
gr.Markdown("# Slideshow mit Audio & automatischen Untertiteln")
|
| 142 |
|
| 143 |
img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
|
| 144 |
-
audio_input = gr.File(
|
|
|
|
|
|
|
|
|
|
| 145 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 146 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 147 |
ypos_input = gr.Slider(minimum=0.0, maximum=0.9, step=0.01, value=0.5, label="Y-Position für alle Texte (0=oben, 0.5=mitte, 0.9=unten)")
|
|
@@ -156,4 +163,4 @@ with gr.Blocks() as demo:
|
|
| 156 |
outputs=[out_video, status]
|
| 157 |
)
|
| 158 |
|
| 159 |
-
demo.launch()
|
|
|
|
| 7 |
import base64
|
| 8 |
import math
|
| 9 |
|
| 10 |
+
# Erlaubte Dateiformate
|
| 11 |
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 12 |
+
allowed_audios = [".mp3", ".wav", ".m4a", ".ogg"]
|
| 13 |
+
|
| 14 |
API_URL = "https://text.pollinations.ai/openai"
|
| 15 |
|
| 16 |
def convert_to_wav(audio_path):
|
|
|
|
| 55 |
segments_per_image = math.ceil(total_words / len(images))
|
| 56 |
texts = []
|
| 57 |
for i in range(len(images)):
|
| 58 |
+
start = i * segments_per_image
|
| 59 |
+
end = min((i + 1) * segments_per_image, total_words)
|
| 60 |
texts.append(" ".join(words[start:end]))
|
| 61 |
else:
|
| 62 |
texts = [""] * len(images)
|
|
|
|
| 72 |
)
|
| 73 |
|
| 74 |
if text:
|
| 75 |
+
# Escape problematische Zeichen
|
| 76 |
+
safe_text = text.replace(":", "\\:").replace("'", "\\'").replace(",", "\\,")
|
| 77 |
drawtext_filter = (
|
| 78 |
f",drawtext=text='{safe_text}':fontcolor=white:fontsize={font_size}:borderw=2:"
|
| 79 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
|
|
|
|
| 145 |
gr.Markdown("# Slideshow mit Audio & automatischen Untertiteln")
|
| 146 |
|
| 147 |
img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
|
| 148 |
+
audio_input = gr.File(
|
| 149 |
+
label="Audio hinzufügen (MP3, WAV, M4A, OGG ... optional)",
|
| 150 |
+
file_types=allowed_audios
|
| 151 |
+
)
|
| 152 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 153 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 154 |
ypos_input = gr.Slider(minimum=0.0, maximum=0.9, step=0.01, value=0.5, label="Y-Position für alle Texte (0=oben, 0.5=mitte, 0.9=unten)")
|
|
|
|
| 163 |
outputs=[out_video, status]
|
| 164 |
)
|
| 165 |
|
| 166 |
+
demo.launch()
|