fionasu commited on
Commit
735cea0
·
verified ·
1 Parent(s): 21dc9ec

reverted it back to pre-pdf

Browse files
Files changed (1) hide show
  1. app.py +3 -35
app.py CHANGED
@@ -1,30 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
-
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
-
28
  theme = gr.themes.Monochrome(
29
  primary_hue=gr.themes.Color(c100="#f5f5f3", c200="#fbfaf8", c300="#f9f9f9", c400="#eee9ee", c50="rgba(255, 255, 255, 1)", c500="rgba(0, 0, 0, 1)", c600="rgba(26.934374999999992, 26.934374999999992, 26.934374999999992, 1)", c700="rgba(10.943750000000012, 10.943750000000012, 10.943750000000012, 1)", c800="rgba(17.053125000000005, 17.053125000000005, 17.053125000000005, 1)", c900="#fffefe", c950="#fffefe"),
30
  secondary_hue=gr.themes.Color(c100="#f29c74", c200="#f4b7a8", c300="#fffefe", c400="#fffefe", c50="#e46e45", c500="#fffefe", c600="#fffefe", c700="#fffefe", c800="#fffefe", c900="#fffefe", c950="#fffefe"),
@@ -190,7 +166,7 @@ def respond(message, history, language, chatbot_mode, destinations, trip_length,
190
  messages = [{
191
  "role": "system",
192
  "content": (
193
- f"You are a friendly and Gen Z travel chatbot helping with packing advice. Do not use any emojis in your response.\n\n"
194
  f"{ctx}\n"
195
  f"Relevant context:\n{str_top_weather}\n{str_top_luggage}"
196
  f"Please respond in {language}"
@@ -200,7 +176,7 @@ def respond(message, history, language, chatbot_mode, destinations, trip_length,
200
  messages = [{
201
  "role": "system",
202
  "content": (
203
- f"You are a friendly and Gen Z travel chatbot recommending food and attractions. Do not use any emojis in your response.\n\n"
204
  f"{ctx}\n"
205
  f"Relevant context:\n{str_top_food}\n{str_top_attraction}"
206
  f"Please respond in {language}"
@@ -210,7 +186,7 @@ def respond(message, history, language, chatbot_mode, destinations, trip_length,
210
  messages = [{
211
  "role": "system",
212
  "content": (
213
- f"You are a friendly and Gen Z travel chatbot helping travelers plan trips to San Francisco and/or Los Angeles. Do not use any emojis in your response.\n\n"
214
  f"{ctx}\n"
215
  f"Use relevant context:\n{str_top_weather}\n{str_top_luggage}\n{str_top_food}\n{str_top_attraction}"
216
  f"Please respond in {language}"
@@ -377,14 +353,6 @@ with gr.Blocks(theme=theme) as demo:
377
  ],
378
  outputs=[chat_box, msg]
379
  )
380
-
381
- pdf_btn = gr.Button("Generate PDF")
382
- pdf_output = gr.File(label="Download Your PDF", height=100)
383
-
384
- def wrapper(chat_history):
385
- return generate_pdf_from_chat(chat_history)
386
-
387
- pdf_btn.click(fn=wrapper, inputs=[chat_box], outputs=[pdf_output])
388
 
389
 
390
  demo.launch(debug=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  theme = gr.themes.Monochrome(
5
  primary_hue=gr.themes.Color(c100="#f5f5f3", c200="#fbfaf8", c300="#f9f9f9", c400="#eee9ee", c50="rgba(255, 255, 255, 1)", c500="rgba(0, 0, 0, 1)", c600="rgba(26.934374999999992, 26.934374999999992, 26.934374999999992, 1)", c700="rgba(10.943750000000012, 10.943750000000012, 10.943750000000012, 1)", c800="rgba(17.053125000000005, 17.053125000000005, 17.053125000000005, 1)", c900="#fffefe", c950="#fffefe"),
6
  secondary_hue=gr.themes.Color(c100="#f29c74", c200="#f4b7a8", c300="#fffefe", c400="#fffefe", c50="#e46e45", c500="#fffefe", c600="#fffefe", c700="#fffefe", c800="#fffefe", c900="#fffefe", c950="#fffefe"),
 
166
  messages = [{
167
  "role": "system",
168
  "content": (
169
+ f"You are a friendly and Gen Z travel chatbot helping with packing advice.\n\n"
170
  f"{ctx}\n"
171
  f"Relevant context:\n{str_top_weather}\n{str_top_luggage}"
172
  f"Please respond in {language}"
 
176
  messages = [{
177
  "role": "system",
178
  "content": (
179
+ f"You are a friendly and Gen Z travel chatbot recommending food and attractions.\n\n"
180
  f"{ctx}\n"
181
  f"Relevant context:\n{str_top_food}\n{str_top_attraction}"
182
  f"Please respond in {language}"
 
186
  messages = [{
187
  "role": "system",
188
  "content": (
189
+ f"You are a friendly and Gen Z travel chatbot helping travelers plan trips to San Francisco and/or Los Angeles.\n\n"
190
  f"{ctx}\n"
191
  f"Use relevant context:\n{str_top_weather}\n{str_top_luggage}\n{str_top_food}\n{str_top_attraction}"
192
  f"Please respond in {language}"
 
353
  ],
354
  outputs=[chat_box, msg]
355
  )
 
 
 
 
 
 
 
 
356
 
357
 
358
  demo.launch(debug=True)