Update backend/app.py
Browse files- backend/app.py +12 -2
backend/app.py
CHANGED
@@ -2,9 +2,15 @@ from flask import Flask, render_template, request, jsonify
|
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
from chatbot import get_krishna_response
|
5 |
-
from
|
6 |
from countdown import get_countdown
|
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
8 |
load_dotenv()
|
9 |
app = Flask(__name__)
|
10 |
|
@@ -17,8 +23,12 @@ def chat():
|
|
17 |
if request.method == 'POST':
|
18 |
user_input = request.form['message']
|
19 |
reply = get_krishna_response(user_input)
|
|
|
|
|
20 |
return jsonify({'reply': reply})
|
21 |
-
|
|
|
|
|
22 |
|
23 |
@app.route('/message')
|
24 |
def message():
|
|
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
from chatbot import get_krishna_response
|
5 |
+
from image_api import generate_krishna_image, generate_comic_strip
|
6 |
from countdown import get_countdown
|
7 |
+
try:
|
8 |
+
from firebase_config import save_chat_message, get_chat_history
|
9 |
+
firebase_enabled = True
|
10 |
+
except ImportError:
|
11 |
+
firebase_enabled = False
|
12 |
|
13 |
+
# Load environment variables (Hugging Face Space secrets)
|
14 |
load_dotenv()
|
15 |
app = Flask(__name__)
|
16 |
|
|
|
23 |
if request.method == 'POST':
|
24 |
user_input = request.form['message']
|
25 |
reply = get_krishna_response(user_input)
|
26 |
+
if firebase_enabled:
|
27 |
+
save_chat_message(user_input, reply)
|
28 |
return jsonify({'reply': reply})
|
29 |
+
# Fetch chat history for display
|
30 |
+
chat_history = get_chat_history() if firebase_enabled else []
|
31 |
+
return render_template('chat.html', chat_history=chat_history)
|
32 |
|
33 |
@app.route('/message')
|
34 |
def message():
|