Spaces:
Build error
Build error
Update app.py
Browse files86 unmodified lines878889909192939495969798991001011021031041051061071081091101111121135 unmodified lines11912012112212312412512612786 unmodified linesprint(f"API request failed: {e}")return None# Function to generate follow-up questions using Geminidef generate_follow_up_questions(user_input, bot_response):url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={gemini_api_key}"headers = {"Content-Type": "application/json"}data = {"contents": [{"parts": [{"text": f"Based on the user's question: '{user_input}' and the response: '{bot_response}', generate three relevant follow-up questions in a numbered list."}]}]}try:response = requests.post(url, json=data, headers=headers)response.raise_for_status()response_data = response.json()if "candidates" in response_data and len(response_data["candidates"]) > 0:return response_data["candidates"][0]["content"]["parts"][0]["text"].strip()return ""except requests.exceptions.RequestException as e:print(f"Failed to generate follow-up questions: {e}")return ""# Function to generate chatbot responsedef generate_bot_response(user_input):global resources5 unmodified linesrelevant_text += f"\n\n**From {filename}:**\n{relevant_section}\n"bot_response = query_gemini_api(relevant_text, user_input) if relevant_text else "I couldn't find relevant information."follow_up_questions = generate_follow_up_questions(user_input, bot_response)return bot_response + "\n\n**Follow-up Questions:**\n" + follow_up_questions# Function to handle chat interactiondef chatbot_response(message, history):86 unmodified lines8788899091925 unmodified lines989910010110210310410586 unmodified linesprint(f"API request failed: {e}")return None# Function to generate chatbot responsedef generate_bot_response(user_input):global resources5 unmodified linesrelevant_text += f"\n\n**From {filename}:**\n{relevant_section}\n"bot_response = query_gemini_api(relevant_text, user_input) if relevant_text else "I couldn't find relevant information."return bot_response# Function to handle chat interactiondef chatbot_response(message, history):
app.py+2-24