Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,15 +37,14 @@ def get_uploaded_logo():
|
|
37 |
dst.write(src.read())
|
38 |
return logo_path
|
39 |
|
40 |
-
# Create image slides from text chunks with
|
|
|
|
|
41 |
def create_slides(text, duration, output_folder, max_lines=6):
|
42 |
-
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
43 |
font = ImageFont.truetype(font_path, 48)
|
44 |
logo_path = get_uploaded_logo()
|
45 |
|
46 |
-
emoji_pool = ["π", "β¨", "π‘", "π₯", "π―", "π’", "π§ ", "π₯"]
|
47 |
-
shapes = [(30, 30, 100, 100), (1100, 600, 1250, 700), (640, 360, 680, 400)]
|
48 |
-
|
49 |
chunks = textwrap.wrap(text, width=36)
|
50 |
slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
|
51 |
per_slide_time = duration / len(slides)
|
@@ -55,23 +54,24 @@ def create_slides(text, duration, output_folder, max_lines=6):
|
|
55 |
img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
|
56 |
draw = ImageDraw.Draw(img)
|
57 |
|
58 |
-
#
|
59 |
-
for s in shapes:
|
60 |
-
color = tuple(random.randint(30, 100) for _ in range(3))
|
61 |
-
draw.ellipse(s, fill=color, outline=None)
|
62 |
-
|
63 |
-
# Text
|
64 |
lines = slide_text.split("\n")
|
65 |
total_height = sum([font.getbbox(line)[3] - font.getbbox(line)[1] for line in lines]) + (len(lines)-1)*20
|
66 |
y = max((720 - total_height) // 2, 20)
|
67 |
|
68 |
-
|
69 |
-
decorated = f"{random.choice(emoji_pool)} {line} {random.choice(emoji_pool)}"
|
70 |
-
w = font.getbbox(decorated)[2] - font.getbbox(decorated)[0]
|
71 |
-
draw.text(((1280 - w) // 2, y), decorated, font=font, fill="white")
|
72 |
-
y += font.getbbox(decorated)[3] - font.getbbox(decorated)[1] + 20
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
logo = Image.open(logo_path).convert("RGBA")
|
76 |
logo_width = min(180, int(0.15 * img.width))
|
77 |
logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
|
@@ -131,7 +131,7 @@ iface = gr.Interface(
|
|
131 |
gr.Video(label="Generated AV Summary")
|
132 |
],
|
133 |
title="ποΈ AV Summary Generator (Multislide with Logo & Emojis)",
|
134 |
-
description="Generates a 5/10 sec video summary from article URL with
|
135 |
)
|
136 |
|
137 |
if __name__ == '__main__':
|
|
|
37 |
dst.write(src.read())
|
38 |
return logo_path
|
39 |
|
40 |
+
# Create image slides from text chunks with pasted emoji icons
|
41 |
+
emoji_img_path = "/home/user/app/emoji_fire.png" # pre-uploaded emoji icon (e.g., fire)
|
42 |
+
|
43 |
def create_slides(text, duration, output_folder, max_lines=6):
|
44 |
+
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
45 |
font = ImageFont.truetype(font_path, 48)
|
46 |
logo_path = get_uploaded_logo()
|
47 |
|
|
|
|
|
|
|
48 |
chunks = textwrap.wrap(text, width=36)
|
49 |
slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
|
50 |
per_slide_time = duration / len(slides)
|
|
|
54 |
img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
|
55 |
draw = ImageDraw.Draw(img)
|
56 |
|
57 |
+
# Draw text
|
|
|
|
|
|
|
|
|
|
|
58 |
lines = slide_text.split("\n")
|
59 |
total_height = sum([font.getbbox(line)[3] - font.getbbox(line)[1] for line in lines]) + (len(lines)-1)*20
|
60 |
y = max((720 - total_height) // 2, 20)
|
61 |
|
62 |
+
emoji_img = Image.open(emoji_img_path).resize((48, 48)).convert("RGBA")
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
for line in lines:
|
65 |
+
w = font.getbbox(line)[2] - font.getbbox(line)[0]
|
66 |
+
text_x = (1280 - w) // 2
|
67 |
+
draw.text((text_x, y), line, font=font, fill="white")
|
68 |
+
# Paste emoji left
|
69 |
+
img.paste(emoji_img, (text_x - 60, y), emoji_img)
|
70 |
+
# Paste emoji right
|
71 |
+
img.paste(emoji_img, (text_x + w + 12, y), emoji_img)
|
72 |
+
y += font.getbbox(line)[3] - font.getbbox(line)[1] + 20
|
73 |
+
|
74 |
+
# Paste logo
|
75 |
logo = Image.open(logo_path).convert("RGBA")
|
76 |
logo_width = min(180, int(0.15 * img.width))
|
77 |
logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
|
|
|
131 |
gr.Video(label="Generated AV Summary")
|
132 |
],
|
133 |
title="ποΈ AV Summary Generator (Multislide with Logo & Emojis)",
|
134 |
+
description="Generates a 5/10 sec video summary from article URL with clean text, animated slides, logo, and image-based emojis."
|
135 |
)
|
136 |
|
137 |
if __name__ == '__main__':
|