-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
37 lines (29 loc) · 944 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
from flask import Flask, render_template, request, jsonify
import pprint
import mpampe
import google.generativeai as palm
palm.configure(api_key='AIzaSyDslGELzeDfdc3DLufleR1y2Reie8RSGfk')
model = palm.get_model('models/chat-bison-001')
app = Flask(__name__, template_folder='templates', static_folder='static')
@app.route("/")
def index():
return render_template('chat.html')
@app.route("/get", methods=["POST"])
def chat():
if request.method == "POST":
msg = request.form["msg"]
response = get_Chat_response(msg)
return response
def get_Chat_response(prompt):
response = palm.chat(
context=mpampe.MpaMpe,
model=model,
messages=[prompt]
)
# Extract Response Here
bot_response = response.messages[-1]['content']
# You can also print the entire response for debugging purposes
print(response)
return bot_response
if __name__ == '__main__':
app.run()