Update app.py
Browse files390 unmodified lines39139239339439539639750 unmodified lines44844945045145245345411 unmodified lines4664674684694704714723 unmodified lines476477478479480481482390 unmodified lines)full_response = generate_chunked_response(model, formatted_prompt)answer = extract_answer(full_response)all_answers.append(answer)break50 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:",11 unmodified linesfull_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\.",3 unmodified linesfor pattern in cleanup_patterns:full_response = re.sub(pattern, "", full_response, flags=re.IGNORECASE).strip()return full_response# Gradio interfacewith gr.Blocks() as demo:390 unmodified lines39139239339439539639750 unmodified lines44844945045145245345411 unmodified lines4664674684694704714723 unmodified lines476477478479480481482483484485486487390 unmodified lines)full_response = generate_chunked_response(model, formatted_prompt)answer = extract_answer(full_response, instructions)all_answers.append(answer)break50 unmodified linesreturn "An unexpected error occurred. Please try again later."def extract_answer(full_response, instructions=None):# 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:",11 unmodified linesfull_response = match[-1].strip()break# 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\.",3 unmodified linesfor pattern in cleanup_patterns:full_response = re.sub(pattern, "", full_response, flags=re.IGNORECASE).strip()# Remove the user instructions if presentif instructions:instruction_pattern = rf"User Instructions:\s*{re.escape(instructions)}.*?\n"full_response = re.sub(instruction_pattern, "", full_response, flags=re.IGNORECASE | re.DOTALL)return full_response.strip()# Gradio interfacewith gr.Blocks() as demo:
app.py+9-4