RohitCSharp commited on
Commit
8692d18
·
verified ·
1 Parent(s): d36132c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -28,7 +28,7 @@ def extract_main_content(url):
28
  paras = [p.get_text() for p in soup.find_all("p") if len(p.get_text()) > 60]
29
  return "\n".join(paras[:20]) or None
30
 
31
- # Convert uploaded PNG logo to local use (as SVG substitute if needed)
32
  def get_uploaded_logo():
33
  from_path = "CSHARP logo.png"
34
  logo_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
@@ -52,11 +52,11 @@ def create_slides(text, duration, output_folder, max_lines=6):
52
  draw = ImageDraw.Draw(img)
53
 
54
  lines = slide_text.split("\n")
55
- total_height = sum([font.getsize(line)[1] for line in lines]) + (len(lines)-1)*10
56
  y = (720 - total_height) // 2
57
 
58
  for line in lines:
59
- w, h = draw.textsize(line, font=font)
60
  draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
61
  y += h + 10
62
 
@@ -74,7 +74,7 @@ def url_to_av_summary(url, duration):
74
  content = extract_main_content(url)
75
  if not content:
76
  return "Failed to extract article content.", None
77
- summary = summary_chain.run(text=content[:3000]).replace('"','')[:300]
78
 
79
  audio_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3").name
80
  gTTS(text=summary).save(audio_path)
 
28
  paras = [p.get_text() for p in soup.find_all("p") if len(p.get_text()) > 60]
29
  return "\n".join(paras[:20]) or None
30
 
31
+ # Convert uploaded PNG logo to local use
32
  def get_uploaded_logo():
33
  from_path = "CSHARP logo.png"
34
  logo_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
 
52
  draw = ImageDraw.Draw(img)
53
 
54
  lines = slide_text.split("\n")
55
+ total_height = sum([draw.textbbox((0, 0), line, font=font)[3] for line in lines]) + (len(lines)-1)*10
56
  y = (720 - total_height) // 2
57
 
58
  for line in lines:
59
+ w, h = draw.textbbox((0, 0), line, font=font)[2:]
60
  draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
61
  y += h + 10
62
 
 
74
  content = extract_main_content(url)
75
  if not content:
76
  return "Failed to extract article content.", None
77
+ summary = summary_chain.invoke({"text": content[:3000]})["text"].replace('"','')[:300]
78
 
79
  audio_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3").name
80
  gTTS(text=summary).save(audio_path)