Kaushik066 commited on
Commit
bc01ca0
·
verified ·
1 Parent(s): f8cb3ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  # generic libraries
2
  import gradio as gr
3
  import os
 
4
 
5
  # for embeddings and indexing
6
  from langchain_huggingface import HuggingFaceEmbeddings
@@ -51,8 +52,25 @@ def respond(message, history #,
51
  #generate results
52
  result = qa_chain.invoke(message)
53
  responce = result['result']
54
-
55
- yield responce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
  demo = gr.ChatInterface(
 
1
  # generic libraries
2
  import gradio as gr
3
  import os
4
+ import re
5
 
6
  # for embeddings and indexing
7
  from langchain_huggingface import HuggingFaceEmbeddings
 
52
  #generate results
53
  result = qa_chain.invoke(message)
54
  responce = result['result']
55
+
56
+ # remove the top instructions
57
+ instruction_prefix = (
58
+ "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer."
59
+ )
60
+ if responce.strip().startswith(instruction_prefix):
61
+ responce = responce.strip()[len(instruction_prefix):].strip()
62
+
63
+ # Split question, Helpful Answer and Reason
64
+ match = re.search(
65
+ r"^(.*?)(?:\n+)?Question:\s*(.*?)(?:\n+)?Helpful Answer:\s*(.*)", responce, re.DOTALL
66
+ )
67
+ if match:
68
+ original_text = match.group(1).strip()
69
+ question = match.group(2).strip()
70
+ answer = match.group(3).strip()
71
+
72
+ formatted_responce = {'Question':question, 'Responce':answer,'reasoning':original_text}
73
+ yield formatted_responce
74
 
75
 
76
  demo = gr.ChatInterface(