Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -112,6 +112,21 @@ def upload_files(files):
|
|
112 |
print(f"Error processing files: {e}")
|
113 |
return f"Error processing files: {e}"
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
def query_text(text):
|
116 |
try:
|
117 |
print(f"Query text: {text}") # Debug: Show the query text
|
@@ -134,7 +149,15 @@ def query_text(text):
|
|
134 |
# Remove duplicates and sort by relevance
|
135 |
top_documents = list(dict.fromkeys(top_documents))
|
136 |
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
except Exception as e:
|
139 |
print(f"Error querying text: {e}")
|
140 |
return f"Error querying text: {e}"
|
@@ -171,6 +194,7 @@ demo.launch()
|
|
171 |
|
172 |
|
173 |
|
|
|
174 |
|
175 |
|
176 |
|
|
|
112 |
print(f"Error processing files: {e}")
|
113 |
return f"Error processing files: {e}"
|
114 |
|
115 |
+
# Prompt template for detailed responses
|
116 |
+
prompt_template = """
|
117 |
+
Answer the question as detailed as possible from the provided context.
|
118 |
+
If the answer is not in the provided context, just say, "answer is not available in the context".
|
119 |
+
Don't provide the wrong answer.
|
120 |
+
|
121 |
+
Context:
|
122 |
+
{context}
|
123 |
+
|
124 |
+
Question:
|
125 |
+
{question}
|
126 |
+
|
127 |
+
Answer:
|
128 |
+
"""
|
129 |
+
|
130 |
def query_text(text):
|
131 |
try:
|
132 |
print(f"Query text: {text}") # Debug: Show the query text
|
|
|
149 |
# Remove duplicates and sort by relevance
|
150 |
top_documents = list(dict.fromkeys(top_documents))
|
151 |
|
152 |
+
# Join the top documents for the context
|
153 |
+
context = "\n".join(top_documents)
|
154 |
+
|
155 |
+
# Prepare the prompt
|
156 |
+
prompt = prompt_template.format(context=context, question=text)
|
157 |
+
|
158 |
+
# Query the LLM
|
159 |
+
response = llm(prompt)
|
160 |
+
return response
|
161 |
except Exception as e:
|
162 |
print(f"Error querying text: {e}")
|
163 |
return f"Error querying text: {e}"
|
|
|
194 |
|
195 |
|
196 |
|
197 |
+
|
198 |
|
199 |
|
200 |
|