fionasu commited on
Commit
ce3c57c
·
verified ·
1 Parent(s): 8eaeed4

udated the pdf function

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -8,10 +8,7 @@ import uuid
8
  from urllib.request import urlretrieve
9
  import os
10
 
11
- FONT_PATH = "NotoSans-Regular.ttf"
12
-
13
- pdf.add_font("NotoSans", "", FONT_PATH, uni=True)
14
- pdf.set_font("NotoSans", size=12)
15
 
16
  def generate_pdf_from_chat(chat_history):
17
  if not chat_history or not isinstance(chat_history, list):
@@ -24,22 +21,22 @@ def generate_pdf_from_chat(chat_history):
24
 
25
  file_path = f"/tmp/chat_response_{uuid.uuid4().hex}.pdf"
26
 
27
- # Create PDF with Unicode support
28
  pdf = FPDF()
29
  pdf.add_page()
30
 
31
- # Register Unicode font
32
- pdf.add_font("NotoSans", "", FONT_PATH, uni=True)
33
- pdf.set_font("NotoSans", size=12)
 
34
  pdf.set_auto_page_break(auto=True, margin=15)
35
 
36
- # Add the text safely
37
  for line in last_response.split("\n"):
38
  pdf.multi_cell(0, 10, line)
39
 
40
  pdf.output(file_path)
41
  return file_path
42
 
 
43
  #_______________________________________________________________________
44
 
45
  theme = gr.themes.Monochrome(
 
8
  from urllib.request import urlretrieve
9
  import os
10
 
11
+ FONT_PATH = "Jost-VariableFont_wght.ttf"
 
 
 
12
 
13
  def generate_pdf_from_chat(chat_history):
14
  if not chat_history or not isinstance(chat_history, list):
 
21
 
22
  file_path = f"/tmp/chat_response_{uuid.uuid4().hex}.pdf"
23
 
 
24
  pdf = FPDF()
25
  pdf.add_page()
26
 
27
+ # Register font (make sure the .ttf file is uploaded to your repo!)
28
+ FONT_PATH = "Jost-VariableFont_wght.ttf"
29
+ pdf.add_font("Jost", "", FONT_PATH, uni=True)
30
+ pdf.set_font("Jost", size=12)
31
  pdf.set_auto_page_break(auto=True, margin=15)
32
 
 
33
  for line in last_response.split("\n"):
34
  pdf.multi_cell(0, 10, line)
35
 
36
  pdf.output(file_path)
37
  return file_path
38
 
39
+
40
  #_______________________________________________________________________
41
 
42
  theme = gr.themes.Monochrome(