Spaces:
Sleeping
Sleeping
revert back to pre - pdf
Browse files
app.py
CHANGED
|
@@ -1,11 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
from fpdf import FPDF
|
| 6 |
-
import uuid
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
#STEP 1 FROM SEMATIC SEARCH
|
| 10 |
from sentence_transformers import SentenceTransformer
|
| 11 |
import torch
|
|
@@ -103,19 +98,6 @@ def get_top_chunks(query, chunk_embeddings, text_chunks):
|
|
| 103 |
# # Print the top results
|
| 104 |
# print(top_weather)
|
| 105 |
|
| 106 |
-
def generate_pdf(content, filename="chatbot_response.pdf"):
|
| 107 |
-
pdf = FPDF()
|
| 108 |
-
pdf.add_page()
|
| 109 |
-
pdf.set_font("Arial", size=12)
|
| 110 |
-
|
| 111 |
-
# Add the text line by line
|
| 112 |
-
for line in content.split("\n"):
|
| 113 |
-
pdf.multi_cell(0, 10, line)
|
| 114 |
-
|
| 115 |
-
unique_filename = f"/mnt/data/{uuid.uuid4()}_{filename}"
|
| 116 |
-
pdf.output(unique_filename)
|
| 117 |
-
return unique_filename
|
| 118 |
-
|
| 119 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
| 120 |
|
| 121 |
def respond(message, history, language, chatbot_mode, destinations, trip_length, trip_unit, trip_season, luggage_types, luggage_size, food_prefs, activity):
|
|
@@ -211,20 +193,8 @@ def respond(message, history, language, chatbot_mode, destinations, trip_length,
|
|
| 211 |
reply = response.strip()
|
| 212 |
|
| 213 |
history.append((message, reply))
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
if "pdf" in message.lower():
|
| 218 |
-
pdf_path = generate_pdf(reply)
|
| 219 |
-
pdf_link = pdf_path
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
if pdf_link:
|
| 223 |
-
return history, "", gr.update(value=pdf_link, visible=True)
|
| 224 |
-
else:
|
| 225 |
-
return history, "", gr.update(visible=False)
|
| 226 |
-
#return history, "", pdf_link
|
| 227 |
-
|
| 228 |
def reset_inputs():
|
| 229 |
return (
|
| 230 |
None, # language
|
|
@@ -260,7 +230,7 @@ with gr.Blocks() as demo:
|
|
| 260 |
gr.Markdown("### Trip Length")
|
| 261 |
trip_length = gr.Number(label="How long is your trip?", precision=0)
|
| 262 |
trip_unit = gr.Radio(
|
| 263 |
-
choices=["day", "week", "month"],
|
| 264 |
label="Trip length unit:"
|
| 265 |
)
|
| 266 |
trip_season = gr.Radio(
|
|
@@ -327,30 +297,43 @@ with gr.Blocks() as demo:
|
|
| 327 |
# 3) send button
|
| 328 |
send_btn = gr.Button("Send")
|
| 329 |
|
| 330 |
-
pdf_output = gr.File(label="Download PDF", visible=False)
|
| 331 |
-
|
| 332 |
-
|
| 333 |
# 4) hook up the click event
|
| 334 |
send_btn.click(
|
| 335 |
fn=respond,
|
| 336 |
inputs=[
|
| 337 |
-
msg,
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
],
|
| 341 |
-
outputs=[chat_box, msg
|
| 342 |
-
)
|
| 343 |
msg.submit(
|
| 344 |
fn=respond,
|
| 345 |
inputs=[
|
| 346 |
-
msg,
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
],
|
| 350 |
-
outputs=[chat_box, msg
|
| 351 |
)
|
| 352 |
-
|
| 353 |
-
|
| 354 |
|
| 355 |
|
| 356 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
#STEP 1 FROM SEMATIC SEARCH
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
import torch
|
|
|
|
| 98 |
# # Print the top results
|
| 99 |
# print(top_weather)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
| 102 |
|
| 103 |
def respond(message, history, language, chatbot_mode, destinations, trip_length, trip_unit, trip_season, luggage_types, luggage_size, food_prefs, activity):
|
|
|
|
| 193 |
reply = response.strip()
|
| 194 |
|
| 195 |
history.append((message, reply))
|
| 196 |
+
return history, ""
|
| 197 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
def reset_inputs():
|
| 199 |
return (
|
| 200 |
None, # language
|
|
|
|
| 230 |
gr.Markdown("### Trip Length")
|
| 231 |
trip_length = gr.Number(label="How long is your trip?", precision=0)
|
| 232 |
trip_unit = gr.Radio(
|
| 233 |
+
choices=["day(s)", "week(s)", "month(s)"],
|
| 234 |
label="Trip length unit:"
|
| 235 |
)
|
| 236 |
trip_season = gr.Radio(
|
|
|
|
| 297 |
# 3) send button
|
| 298 |
send_btn = gr.Button("Send")
|
| 299 |
|
|
|
|
|
|
|
|
|
|
| 300 |
# 4) hook up the click event
|
| 301 |
send_btn.click(
|
| 302 |
fn=respond,
|
| 303 |
inputs=[
|
| 304 |
+
msg,
|
| 305 |
+
chat_box,
|
| 306 |
+
language,
|
| 307 |
+
chatbot_mode,
|
| 308 |
+
destinations,
|
| 309 |
+
trip_length,
|
| 310 |
+
trip_unit,
|
| 311 |
+
trip_season,
|
| 312 |
+
luggage_types,
|
| 313 |
+
luggage_size,
|
| 314 |
+
food_prefs,
|
| 315 |
+
activity
|
| 316 |
],
|
| 317 |
+
outputs=[chat_box, msg]
|
| 318 |
+
)
|
| 319 |
msg.submit(
|
| 320 |
fn=respond,
|
| 321 |
inputs=[
|
| 322 |
+
msg,
|
| 323 |
+
chat_box,
|
| 324 |
+
language,
|
| 325 |
+
chatbot_mode,
|
| 326 |
+
destinations,
|
| 327 |
+
trip_length,
|
| 328 |
+
trip_unit,
|
| 329 |
+
trip_season,
|
| 330 |
+
luggage_types,
|
| 331 |
+
luggage_size,
|
| 332 |
+
food_prefs,
|
| 333 |
+
activity
|
| 334 |
],
|
| 335 |
+
outputs=[chat_box, msg]
|
| 336 |
)
|
|
|
|
|
|
|
| 337 |
|
| 338 |
|
| 339 |
|