Update app.py
Browse files396 unmodified lines3973983994004014021 unmodified line404405406407408409410411412413414415416417418419396 unmodified linesreturn "An unexpected error occurred. Please try again later."def extract_answer(full_response):answer_patterns = [r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:",r"Provide a concise and direct answer to the question:",1 unmodified liner"Provide a summarized and direct answer to the question.",r"If the context doesn't contain relevant information, state that the information is not available in the document.",r"Provide a summarized and direct answer to the original question without mentioning the web search or these instructions:",r"without mentioning the web search or these instructions.",r"Do not include any source information in your answer:",r"Do not include any source information in your answer."]for pattern in answer_patterns:match = re.split(pattern, full_response, flags=re.IGNORECASE)if len(match) > 1:return match[-1].strip()return full_response.strip()# Gradio interfacewith gr.Blocks() as demo:396 unmodified lines3973983994004014024031 unmodified line405406407408409410411412413414415416417418419420421422423424425426427428429430396 unmodified linesreturn "An unexpected error occurred. Please try again later."def extract_answer(full_response):# First, try to split the response at common instruction phrasesanswer_patterns = [r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:",r"Provide a concise and direct answer to the question:",1 unmodified liner"Provide a summarized and direct answer to the question.",r"If the context doesn't contain relevant information, state that the information is not available in the document.",r"Provide a summarized and direct answer to the original question without mentioning the web search or these instructions:",r"Do not include any source information in your answer."]for pattern in answer_patterns:match = re.split(pattern, full_response, flags=re.IGNORECASE)if len(match) > 1:full_response = match[-1].strip()break# Then, remove any remaining instruction-like phrasescleanup_patterns = [r"without mentioning the web search or these instructions\.",r"Do not include any source information in your answer\.",r"If the context doesn't contain relevant information, state that the information is not available in the document\."]for pattern in cleanup_patterns:full_response = re.sub(pattern, "", full_response, flags=re.IGNORECASE).strip()return full_response# Gradio interfacewith gr.Blocks() as demo:
app.py+15-4