RohitCSharp commited on
Commit
da2d8c5
Β·
verified Β·
1 Parent(s): 473c60d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -8,6 +8,7 @@ from bs4 import BeautifulSoup
8
  from PIL import Image, ImageDraw, ImageFont
9
  import ffmpeg
10
  import textwrap
 
11
 
12
  # OpenAI LLM
13
  llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.3)
@@ -36,12 +37,15 @@ def get_uploaded_logo():
36
  dst.write(src.read())
37
  return logo_path
38
 
39
- # Create image slides from text chunks
40
  def create_slides(text, duration, output_folder, max_lines=6):
41
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
42
  font = ImageFont.truetype(font_path, 48)
43
  logo_path = get_uploaded_logo()
44
 
 
 
 
45
  chunks = textwrap.wrap(text, width=36)
46
  slides = ["\n".join(chunks[i:i+max_lines]) for i in range(0, len(chunks), max_lines)]
47
  per_slide_time = duration / len(slides)
@@ -51,6 +55,12 @@ def create_slides(text, duration, output_folder, max_lines=6):
51
  img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
52
  draw = ImageDraw.Draw(img)
53
 
 
 
 
 
 
 
54
  lines = slide_text.split("\n")
55
  line_sizes = [draw.textbbox((0, 0), line, font=font) for line in lines]
56
  total_height = sum([b[3] - b[1] for b in line_sizes]) + (len(lines)-1)*20
@@ -59,9 +69,11 @@ def create_slides(text, duration, output_folder, max_lines=6):
59
  for line, bbox in zip(lines, line_sizes):
60
  w = bbox[2] - bbox[0]
61
  h = bbox[3] - bbox[1]
62
- draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
 
63
  y += h + 20
64
 
 
65
  logo = Image.open(logo_path).convert("RGBA")
66
  logo_width = min(180, int(0.15 * img.width))
67
  logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
@@ -120,8 +132,8 @@ iface = gr.Interface(
120
  gr.Textbox(label="Summary"),
121
  gr.Video(label="Generated AV Summary")
122
  ],
123
- title="🎞️ AV Summary Generator (Multislide with Uploaded Logo)",
124
- description="Generates a 5/10 sec video summary from article URL with large text, uploaded logo, and slide animation."
125
  )
126
 
127
  if __name__ == '__main__':
 
8
  from PIL import Image, ImageDraw, ImageFont
9
  import ffmpeg
10
  import textwrap
11
+ import random
12
 
13
  # OpenAI LLM
14
  llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.3)
 
37
  dst.write(src.read())
38
  return logo_path
39
 
40
+ # Create image slides from text chunks with emojis and shapes
41
  def create_slides(text, duration, output_folder, max_lines=6):
42
  font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.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
  img = Image.new("RGB", (1280, 720), color=(20, 30, 60))
56
  draw = ImageDraw.Draw(img)
57
 
58
+ # Add random shapes
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
  line_sizes = [draw.textbbox((0, 0), line, font=font) for line in lines]
66
  total_height = sum([b[3] - b[1] for b in line_sizes]) + (len(lines)-1)*20
 
69
  for line, bbox in zip(lines, line_sizes):
70
  w = bbox[2] - bbox[0]
71
  h = bbox[3] - bbox[1]
72
+ decorated = random.choice(emoji_pool) + " " + line + " " + random.choice(emoji_pool)
73
+ draw.text(((1280 - w) // 2, y), decorated, font=font, fill="white")
74
  y += h + 20
75
 
76
+ # Logo
77
  logo = Image.open(logo_path).convert("RGBA")
78
  logo_width = min(180, int(0.15 * img.width))
79
  logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
 
132
  gr.Textbox(label="Summary"),
133
  gr.Video(label="Generated AV Summary")
134
  ],
135
+ title="🎞️ AV Summary Generator (Multislide with Logo & Emojis)",
136
+ description="Generates a 5/10 sec video summary from article URL with large text, animated slides, logo, emojis, and shapes."
137
  )
138
 
139
  if __name__ == '__main__':