Spaces:
Running
Running
Commit
·
f2b8ccd
1
Parent(s):
f582c24
Final: Updated app.py
Browse files
app.py
CHANGED
|
@@ -151,21 +151,23 @@ def ask_question(question):
|
|
| 151 |
|
| 152 |
context = "\n".join([doc.page_content for doc in docs])
|
| 153 |
prompt = generate_prompt(context, question)
|
| 154 |
-
|
| 155 |
|
| 156 |
-
#
|
| 157 |
-
for
|
| 158 |
-
|
| 159 |
|
| 160 |
-
# Remove
|
| 161 |
-
if "Answer:" in
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
#
|
| 165 |
-
if
|
| 166 |
-
|
| 167 |
|
| 168 |
-
return post_process_output(
|
| 169 |
|
| 170 |
|
| 171 |
# Gradio UI
|
|
|
|
| 151 |
|
| 152 |
context = "\n".join([doc.page_content for doc in docs])
|
| 153 |
prompt = generate_prompt(context, question)
|
| 154 |
+
response = reasoning_pipeline(prompt)[0]['generated_text']
|
| 155 |
|
| 156 |
+
# Clean out prompt leakage
|
| 157 |
+
for token in ["Context:", "Question:", "Instructions:", "Use structured academic language"]:
|
| 158 |
+
response = response.replace(token, "").strip()
|
| 159 |
|
| 160 |
+
# Remove leading/trailing junk
|
| 161 |
+
if "Answer:" in response:
|
| 162 |
+
response = response.split("Answer:")[-1].strip()
|
| 163 |
+
if "." in response:
|
| 164 |
+
response = response.rsplit(".", 1)[0] + "."
|
| 165 |
|
| 166 |
+
# ❗ Fallback if answer is empty or nonsense
|
| 167 |
+
if len(response.strip()) < 10:
|
| 168 |
+
return "❌ The model could not generate a meaningful answer based on the provided context."
|
| 169 |
|
| 170 |
+
return post_process_output(response.strip(), question)
|
| 171 |
|
| 172 |
|
| 173 |
# Gradio UI
|