umerforsure commited on
Commit
f582c24
·
1 Parent(s): 0c32660

Final: Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -151,9 +151,22 @@ def ask_question(question):
151
 
152
  context = "\n".join([doc.page_content for doc in docs])
153
  prompt = generate_prompt(context, question)
154
- result = reasoning_pipeline(prompt)[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
- return post_process_output(result, question)
157
 
158
  # Gradio UI
159
  with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
 
151
 
152
  context = "\n".join([doc.page_content for doc in docs])
153
  prompt = generate_prompt(context, question)
154
+ raw_output = reasoning_pipeline(prompt)[0]['generated_text']
155
+
156
+ # 🧠 Smart cleanup: remove prompt leakage or echoed instructions
157
+ for section in ["Context:", "Question:", "Instructions:", "Use structured academic language"]:
158
+ raw_output = raw_output.replace(section, "").strip()
159
+
160
+ # Remove anything before answer starts if needed
161
+ if "Answer:" in raw_output:
162
+ raw_output = raw_output.split("Answer:")[-1].strip()
163
+
164
+ # Trim trailing junk
165
+ if "." in raw_output:
166
+ raw_output = raw_output.rsplit(".", 1)[0] + "."
167
+
168
+ return post_process_output(raw_output.strip(), question)
169
 
 
170
 
171
  # Gradio UI
172
  with gr.Blocks(theme=gr.themes.Monochrome()) as demo: