-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (31 loc) · 933 Bytes
/
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
import os
from dotenv import load_dotenv
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
import google.generativeai as genai
load_dotenv()
app = Flask(__name__)
CORS(app)
API_KEY = os.getenv("API_KEY")
genai.configure(api_key=API_KEY)
@app.route('/')
def index():
return render_template('index.html')
@app.route("/api/generate", methods=["POST"])
def generate_content():
data = request.json
user_input = data.get("input")
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 500,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
)
response = model.generate_content(user_input)
return jsonify({"response": response.text})
if __name__ == "__main__":
app.run(debug=True)