Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from flask import Flask, render_template, request, session
|
| 2 |
-
|
| 3 |
-
from
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
-
app.secret_key = "
|
| 7 |
|
| 8 |
-
#
|
|
|
|
|
|
|
| 9 |
parrot_images = {
|
| 10 |
"행복": "parrot-happy.png",
|
| 11 |
"슬픔": "parrot-sad.png",
|
|
@@ -16,21 +24,24 @@ parrot_images = {
|
|
| 16 |
"놀람": "parrot-surprise.png",
|
| 17 |
}
|
| 18 |
|
| 19 |
-
# 감정별 앵무새 반응 문구
|
| 20 |
parrot_responses = {
|
| 21 |
"행복": "와! 당신이 행복해서 저도 기분 좋아요! 🎉",
|
| 22 |
"슬픔": "슬프다니, 제가 옆에서 힘이 되어줄게요... 🥺",
|
| 23 |
-
"분노": "화났군요!
|
| 24 |
"중립": "괜찮아요, 평온한 하루도 필요하죠.",
|
| 25 |
"혐오": "그런 감정도 있어요. 힘내요!",
|
| 26 |
"공포": "겁나는 상황이군요. 제가 지켜드릴게요!",
|
| 27 |
"놀람": "우와, 놀랐나요? 저도 깜짝 놀랐어요! 😲",
|
| 28 |
}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
@app.route("/")
|
| 31 |
def index():
|
| 32 |
return render_template("index.html")
|
| 33 |
|
|
|
|
| 34 |
@app.route("/chat", methods=["GET", "POST"])
|
| 35 |
def chat():
|
| 36 |
if "chat_history" not in session:
|
|
@@ -44,7 +55,7 @@ def chat():
|
|
| 44 |
parrot_img = parrot_images.get(emotion, "parrot-neutral.png")
|
| 45 |
parrot_reply = parrot_responses.get(emotion, "제가 듣고 있어요.")
|
| 46 |
|
| 47 |
-
# 노래 추천
|
| 48 |
songs = None
|
| 49 |
if "노래추천해줘" in user_message or "노래 추천" in user_message:
|
| 50 |
songs = search_spotify(emotion)
|
|
@@ -66,10 +77,12 @@ def chat():
|
|
| 66 |
else:
|
| 67 |
return render_template("chat.html", chat_history=session.get("chat_history", []))
|
| 68 |
|
|
|
|
| 69 |
@app.route("/reset")
|
| 70 |
def reset():
|
| 71 |
session.pop("chat_history", None)
|
| 72 |
return render_template("index.html")
|
| 73 |
|
|
|
|
| 74 |
if __name__ == "__main__":
|
| 75 |
app.run(host="0.0.0.0", port=5000, debug=True)
|
|
|
|
| 1 |
+
# ==============================
|
| 2 |
+
# app.py
|
| 3 |
+
# KoBERT 감정 분석 + 앵무새 반응 + 노래 추천
|
| 4 |
+
# ==============================
|
| 5 |
+
|
| 6 |
from flask import Flask, render_template, request, session
|
| 7 |
+
import torch
|
| 8 |
+
from kobert_model import predict_emotion # 파인튜닝한 KoBERT 모델
|
| 9 |
+
from spotify_api import search_spotify # Spotify 노래 추천 API
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
+
app.secret_key = "yangtal12345" # 💡 변경 가능
|
| 13 |
|
| 14 |
+
# ==============================
|
| 15 |
+
# 앵무새 이미지 & 반응
|
| 16 |
+
# ==============================
|
| 17 |
parrot_images = {
|
| 18 |
"행복": "parrot-happy.png",
|
| 19 |
"슬픔": "parrot-sad.png",
|
|
|
|
| 24 |
"놀람": "parrot-surprise.png",
|
| 25 |
}
|
| 26 |
|
|
|
|
| 27 |
parrot_responses = {
|
| 28 |
"행복": "와! 당신이 행복해서 저도 기분 좋아요! 🎉",
|
| 29 |
"슬픔": "슬프다니, 제가 옆에서 힘이 되어줄게요... 🥺",
|
| 30 |
+
"분노": "화났군요! 저랑 같이 심호흡 해볼까요? 😤",
|
| 31 |
"중립": "괜찮아요, 평온한 하루도 필요하죠.",
|
| 32 |
"혐오": "그런 감정도 있어요. 힘내요!",
|
| 33 |
"공포": "겁나는 상황이군요. 제가 지켜드릴게요!",
|
| 34 |
"놀람": "우와, 놀랐나요? 저도 깜짝 놀랐어요! 😲",
|
| 35 |
}
|
| 36 |
|
| 37 |
+
# ==============================
|
| 38 |
+
# 라우트
|
| 39 |
+
# ==============================
|
| 40 |
@app.route("/")
|
| 41 |
def index():
|
| 42 |
return render_template("index.html")
|
| 43 |
|
| 44 |
+
|
| 45 |
@app.route("/chat", methods=["GET", "POST"])
|
| 46 |
def chat():
|
| 47 |
if "chat_history" not in session:
|
|
|
|
| 55 |
parrot_img = parrot_images.get(emotion, "parrot-neutral.png")
|
| 56 |
parrot_reply = parrot_responses.get(emotion, "제가 듣고 있어요.")
|
| 57 |
|
| 58 |
+
# 노래 추천
|
| 59 |
songs = None
|
| 60 |
if "노래추천해줘" in user_message or "노래 추천" in user_message:
|
| 61 |
songs = search_spotify(emotion)
|
|
|
|
| 77 |
else:
|
| 78 |
return render_template("chat.html", chat_history=session.get("chat_history", []))
|
| 79 |
|
| 80 |
+
|
| 81 |
@app.route("/reset")
|
| 82 |
def reset():
|
| 83 |
session.pop("chat_history", None)
|
| 84 |
return render_template("index.html")
|
| 85 |
|
| 86 |
+
|
| 87 |
if __name__ == "__main__":
|
| 88 |
app.run(host="0.0.0.0", port=5000, debug=True)
|