Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,11 @@ def query(payload):
|
|
| 19 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 20 |
return response.content
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def extract_paragraphs_by_vertical_spacing(pdf_data, spacing_threshold=10):
|
| 23 |
paragraphs = []
|
| 24 |
|
|
@@ -78,6 +83,7 @@ if uploaded_file is not None:
|
|
| 78 |
|
| 79 |
for paragraph in paragraphs:
|
| 80 |
summary = summarizer(paragraph, max_length=(len(paragraph) / 2), min_length=10, do_sample=False)
|
|
|
|
| 81 |
|
| 82 |
# Create a slide
|
| 83 |
slide = prs.slides.add_slide(prs.slide_layouts[5])
|
|
@@ -91,7 +97,7 @@ if uploaded_file is not None:
|
|
| 91 |
p.text = f"Paragraph {i}:"
|
| 92 |
p.space_after = Inches(0.1)
|
| 93 |
p = tf.add_paragraph()
|
| 94 |
-
p.text =
|
| 95 |
|
| 96 |
# Generate and add the image to the slide
|
| 97 |
image_bytes = query({
|
|
|
|
| 19 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 20 |
return response.content
|
| 21 |
|
| 22 |
+
def add_line_breaks_to_summary(summary_text, line_length):
|
| 23 |
+
# Split the summary text into lines with a maximum line length
|
| 24 |
+
lines = [summary_text[i:i + line_length] for i in range(0, len(summary_text), line_length)]
|
| 25 |
+
return "\n".join(lines)
|
| 26 |
+
|
| 27 |
def extract_paragraphs_by_vertical_spacing(pdf_data, spacing_threshold=10):
|
| 28 |
paragraphs = []
|
| 29 |
|
|
|
|
| 83 |
|
| 84 |
for paragraph in paragraphs:
|
| 85 |
summary = summarizer(paragraph, max_length=(len(paragraph) / 2), min_length=10, do_sample=False)
|
| 86 |
+
summary_text = add_line_breaks_to_summary(summary[0]['summary_text'], 40)
|
| 87 |
|
| 88 |
# Create a slide
|
| 89 |
slide = prs.slides.add_slide(prs.slide_layouts[5])
|
|
|
|
| 97 |
p.text = f"Paragraph {i}:"
|
| 98 |
p.space_after = Inches(0.1)
|
| 99 |
p = tf.add_paragraph()
|
| 100 |
+
p.text = summary_text
|
| 101 |
|
| 102 |
# Generate and add the image to the slide
|
| 103 |
image_bytes = query({
|