Spaces:
Sleeping
Sleeping
abubasith86
commited on
Commit
·
c06c126
1
Parent(s):
e1dd907
Revoke
Browse files
app.py
CHANGED
@@ -37,7 +37,6 @@ Your goals:
|
|
37 |
- Always be polite, helpful, and respectful.
|
38 |
"""
|
39 |
|
40 |
-
|
41 |
def respond(
|
42 |
message,
|
43 |
history: list[tuple[str, str]],
|
@@ -47,39 +46,6 @@ def respond(
|
|
47 |
pdf_file=None,
|
48 |
):
|
49 |
|
50 |
-
recent_keywords = [
|
51 |
-
"latest",
|
52 |
-
"today",
|
53 |
-
"current",
|
54 |
-
"now",
|
55 |
-
"recent",
|
56 |
-
"news",
|
57 |
-
"update",
|
58 |
-
"price",
|
59 |
-
"who won",
|
60 |
-
"what happened",
|
61 |
-
]
|
62 |
-
message_lower = message.lower()
|
63 |
-
|
64 |
-
# Check if this is a recent/live query
|
65 |
-
if any(kw in message_lower for kw in recent_keywords):
|
66 |
-
web_result = search_web(message)
|
67 |
-
if web_result:
|
68 |
-
yield f"[Answer from Web Search]\n{web_result}"
|
69 |
-
return
|
70 |
-
|
71 |
-
# Check if PDF was uploaded
|
72 |
-
context_text = ""
|
73 |
-
if pdf_file is not None:
|
74 |
-
try:
|
75 |
-
context_text = extract_text_from_pdf(pdf_file.name)
|
76 |
-
except Exception as e:
|
77 |
-
yield f"[Error reading PDF: {str(e)}]"
|
78 |
-
|
79 |
-
# Try answering from PDF if context exists
|
80 |
-
if context_text.strip():
|
81 |
-
message = f"Given the following document context:\n\n{context_text[:2000]}\n\nAnswer the question:\n{message}"
|
82 |
-
|
83 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
84 |
|
85 |
for val in history:
|
@@ -120,7 +86,7 @@ demo = gr.ChatInterface(
|
|
120 |
step=0.05,
|
121 |
label="Top-p (nucleus sampling)",
|
122 |
),
|
123 |
-
|
124 |
],
|
125 |
)
|
126 |
|
|
|
37 |
- Always be polite, helpful, and respectful.
|
38 |
"""
|
39 |
|
|
|
40 |
def respond(
|
41 |
message,
|
42 |
history: list[tuple[str, str]],
|
|
|
46 |
pdf_file=None,
|
47 |
):
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
50 |
|
51 |
for val in history:
|
|
|
86 |
step=0.05,
|
87 |
label="Top-p (nucleus sampling)",
|
88 |
),
|
89 |
+
gr.File(label="Upload a PDF", file_types=[".pdf"]),
|
90 |
],
|
91 |
)
|
92 |
|