-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (36 loc) · 1.11 KB
/
app.py
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
42
43
44
45
46
from flask import Flask, render_template, request, jsonify
import os
from dotenv import load_dotenv
import google.generativeai as genai
app = Flask(__name__)
# Load environment variables from the .env file
load_dotenv()
# Retrieve the API key from the environment variable
API_KEY = os.getenv("API_KEY")
# Configure the Gemini API with the API key
genai.configure(api_key=API_KEY)
# Create the model with generation configurations
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
)
# Start a chat session
chat_session = model.start_chat(history=[])
@app.route('/')
def index():
return render_template('index.html')
@app.route('/chat', methods=['POST'])
def chat():
user_input = request.json.get('message')
response = chat_session.send_message(user_input)
return jsonify({"response": response.text})
if __name__ == "__main__":
from waitress import serve
serve(app, host="0.0.0.0", port=5000)