Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,12 +62,12 @@ def generate_itinerary(mood, location, budget, days):
|
|
| 62 |
def generate_pdf(itinerary_text):
|
| 63 |
if not itinerary_text.strip():
|
| 64 |
return None
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
# Prepare the document template with letter page size
|
| 70 |
-
doc = SimpleDocTemplate(
|
| 71 |
rightMargin=40, leftMargin=40,
|
| 72 |
topMargin=40, bottomMargin=40)
|
| 73 |
|
|
@@ -87,15 +87,18 @@ def generate_pdf(itinerary_text):
|
|
| 87 |
# Build the story (list of flowables)
|
| 88 |
story = []
|
| 89 |
for para in paragraphs:
|
|
|
|
| 90 |
if para.strip():
|
| 91 |
-
|
| 92 |
else:
|
| 93 |
-
|
| 94 |
-
story.append(
|
|
|
|
| 95 |
|
|
|
|
| 96 |
doc.build(story)
|
| 97 |
|
| 98 |
-
return
|
| 99 |
|
| 100 |
|
| 101 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")) as demo:
|
|
|
|
| 62 |
def generate_pdf(itinerary_text):
|
| 63 |
if not itinerary_text.strip():
|
| 64 |
return None
|
| 65 |
+
|
| 66 |
+
# Create a temporary PDF file
|
| 67 |
+
temp_pdf = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
| 68 |
|
| 69 |
# Prepare the document template with letter page size
|
| 70 |
+
doc = SimpleDocTemplate(temp_pdf.name, pagesize=letter,
|
| 71 |
rightMargin=40, leftMargin=40,
|
| 72 |
topMargin=40, bottomMargin=40)
|
| 73 |
|
|
|
|
| 87 |
# Build the story (list of flowables)
|
| 88 |
story = []
|
| 89 |
for para in paragraphs:
|
| 90 |
+
# Add Paragraph flowable; empty line if paragraph is empty
|
| 91 |
if para.strip():
|
| 92 |
+
p = Paragraph(para, style)
|
| 93 |
else:
|
| 94 |
+
p = Paragraph(' ', style)
|
| 95 |
+
story.append(p)
|
| 96 |
+
story.append(Spacer(1, 6)) # small space between paragraphs
|
| 97 |
|
| 98 |
+
# Build the PDF document
|
| 99 |
doc.build(story)
|
| 100 |
|
| 101 |
+
return temp_pdf.name
|
| 102 |
|
| 103 |
|
| 104 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="teal", secondary_hue="teal")) as demo:
|