import os import google.generativeai as genai from flask import Flask, request, jsonify, Response from flask_cors import CORS app = Flask(__name__) CORS(app) # --- Konfiguration & Gemini Initialisierung --- GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY") if not GOOGLE_API_KEY: raise ValueError("GOOGLE_API_KEY nicht gesetzt!") genai.configure(api_key=GOOGLE_API_KEY) model = genai.GenerativeModel('gemini-1.5-pro') chat = model.start_chat(history=[]) # --- Info-Startseite für GET / @app.route('/', methods=['GET']) def index(): return Response( "

Moejra Chat API

Die API ist erreichbar. Sende POST-Anfragen an /chat.

", mimetype='text/html' ) # --- API-Endpunkt für POST /chat --- @app.route('/chat', methods=['POST']) def handle_chat(): try: user_input = request.json.get('text') response = chat.send_message(user_input) return jsonify({ "text": response.text, "images": [] }) except Exception as e: return jsonify({"error": str(e)}), 500 if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)