Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,22 +5,23 @@ from huggingface_hub import InferenceClient
|
|
5 |
from fpdf import FPDF
|
6 |
import uuid
|
7 |
|
8 |
-
from urllib.request import urlretrieve
|
9 |
-
import os
|
10 |
-
|
11 |
def generate_pdf_from_chat(chat_history):
|
12 |
pdf = FPDF()
|
13 |
pdf.add_page()
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
for user_msg, bot_msg in chat_history:
|
|
|
17 |
pdf.multi_cell(0, 10, txt=f"User: {user_msg}", align='L')
|
18 |
pdf.multi_cell(0, 10, txt=f"Bot: {bot_msg}", align='L')
|
19 |
pdf.ln(5)
|
20 |
|
21 |
file_path = f"/tmp/travel_chat_{uuid.uuid4().hex}.pdf"
|
22 |
pdf.output(file_path)
|
23 |
-
return file_path
|
24 |
|
25 |
#_______________________________________________________________________
|
26 |
|
|
|
5 |
from fpdf import FPDF
|
6 |
import uuid
|
7 |
|
|
|
|
|
|
|
8 |
def generate_pdf_from_chat(chat_history):
|
9 |
pdf = FPDF()
|
10 |
pdf.add_page()
|
11 |
+
|
12 |
+
# Add a Unicode TTF font (path to your DejaVuSans.ttf file)
|
13 |
+
pdf.add_font("DejaVu", "", "DejaVuSans.ttf", uni=True)
|
14 |
+
pdf.set_font("DejaVu", size=12)
|
15 |
|
16 |
for user_msg, bot_msg in chat_history:
|
17 |
+
# Now you can safely use UTF-8 strings with curly quotes, emojis, etc.
|
18 |
pdf.multi_cell(0, 10, txt=f"User: {user_msg}", align='L')
|
19 |
pdf.multi_cell(0, 10, txt=f"Bot: {bot_msg}", align='L')
|
20 |
pdf.ln(5)
|
21 |
|
22 |
file_path = f"/tmp/travel_chat_{uuid.uuid4().hex}.pdf"
|
23 |
pdf.output(file_path)
|
24 |
+
return file_path
|
25 |
|
26 |
#_______________________________________________________________________
|
27 |
|