Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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([
|
56 |
y = (720 - total_height) // 2
|
57 |
|
58 |
for line in lines:
|
59 |
-
w, h = draw.
|
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.
|
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)
|