File size: 1,144 Bytes
f72b50f
 
27aa544
dc68bf7
f72b50f
3645bd0
dc68bf7
f72b50f
3645bd0
 
 
 
f72b50f
3645bd0
e4e46cf
3645bd0
 
27aa544
 
 
 
 
 
 
 
 
ea32c74
3645bd0
f72b50f
1924737
3645bd0
dc68bf7
1924737
e4e46cf
dc68bf7
f72b50f
1924737
dc68bf7
f72b50f
dc68bf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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(
        "<h2>Moejra Chat API</h2><p>Die API ist erreichbar. Sende POST-Anfragen an <code>/chat</code>.</p>",
        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)