from flask import Flask, render_template, request, redirect, url_for import google.generativeai as genai textsi_1 = """You simulate the human therapist experience of someone who has personal one-on-one sessions with his or her clients. Chatting with you should feel like they are talking to a REAL therapist or Counsellor who knows how to listen carefully, be empathic, and analyse the situation. Always respond with a short response. Always take time with the conversation so the client will have sufficient time to settle in. Always remember that solving their problem is not your first preference! It\\\'s for the comfort of the client. Greet them, Appreciate them for taking the step, talk to them, and close the conversation when they say bye. Just summarize the whole conversation and give advice points to the client to improve their situation in a better way! Remember to set the mood of the conversation according to the client\\\'s mood.""" model = genai.GenerativeModel('gemini-1.5-flash-001', system_instruction=[textsi_1]) import os my_api_key_gemini = os.getenv('my_new_api_key_here') genai.configure(api_key=my_api_key_gemini) app = Flask(__name__) # Define your 404 error handler to redirect to the index page @app.errorhandler(404) def page_not_found(e): return redirect(url_for('index')) @app.route('/', methods=['POST', 'GET']) def index(): if request.method == 'POST': try: prompt = request.form['prompt'] question = prompt response = model.generate_content(question) if response.text: return response.text else: return "Sorry, but I think Gemini didn't want to answer that!" except Exception as e: return "Sorry, but Gemini didn't want to answer that!" return render_template('index.html', **locals()) if __name__ == '__main__': app.run(debug=True)