Adding Chatbot Feature
Browse files- app.py +13 -2
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,12 +4,23 @@ import mysql.connector
|
|
| 4 |
import os
|
| 5 |
import logging
|
| 6 |
import random
|
|
|
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
| 11 |
-
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# === MySQL Connection ===
|
| 15 |
def get_connection():
|
|
@@ -32,7 +43,7 @@ def root():
|
|
| 32 |
def chat():
|
| 33 |
data = request.get_json()
|
| 34 |
message = data.get("message")
|
| 35 |
-
response =
|
| 36 |
return jsonify({"response": response})
|
| 37 |
|
| 38 |
|
|
|
|
| 4 |
import os
|
| 5 |
import logging
|
| 6 |
import random
|
| 7 |
+
from google import genai
|
| 8 |
|
| 9 |
|
| 10 |
+
|
| 11 |
+
def initialize_model(client,prompt):
|
| 12 |
+
chat = client.chats.create(
|
| 13 |
+
model="gemini-2.0-flash"
|
| 14 |
+
)
|
| 15 |
+
response = chat.send_message(prompt)
|
| 16 |
+
|
| 17 |
+
return chat
|
| 18 |
+
|
| 19 |
app = Flask(__name__)
|
| 20 |
CORS(app)
|
|
|
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
| 22 |
+
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 23 |
+
chats = initialize_model(client,os.getenv("SYSTEM_PROMPT"))
|
| 24 |
|
| 25 |
# === MySQL Connection ===
|
| 26 |
def get_connection():
|
|
|
|
| 43 |
def chat():
|
| 44 |
data = request.get_json()
|
| 45 |
message = data.get("message")
|
| 46 |
+
response = chat.send_message(message)
|
| 47 |
return jsonify({"response": response})
|
| 48 |
|
| 49 |
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@
|
|
| 5 |
pydantic
|
| 6 |
Flask
|
| 7 |
Flask-Cors
|
| 8 |
-
werkzeug
|
|
|
|
|
|
| 5 |
pydantic
|
| 6 |
Flask
|
| 7 |
Flask-Cors
|
| 8 |
+
werkzeug
|
| 9 |
+
google-genai
|