Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,21 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from textblob import TextBlob
|
| 4 |
from src.inference import predict
|
| 5 |
-
from src.responses import get_response
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
if
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
user = str(TextBlob(user).correct())
|
| 16 |
-
|
| 17 |
-
# if any negative phrase → force sadness,
|
| 18 |
-
# else run model inference
|
| 19 |
-
if any(phrase in user.lower() for phrase in negative_inputs):
|
| 20 |
-
emotion = "sadness"
|
| 21 |
-
else:
|
| 22 |
-
emotion = predict(user)
|
| 23 |
-
|
| 24 |
-
reply, done = get_response(emotion, user)
|
| 25 |
-
print(f"EmotiBot 🌿: {reply}")
|
| 26 |
if done:
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
if not os.path.exists('emotion_transformer_model.pth'):
|
| 3 |
+
from src.train_transformer import train
|
| 4 |
+
train()
|
| 5 |
|
| 6 |
+
# 2) Streamlit UI
|
| 7 |
+
import streamlit as st
|
| 8 |
from textblob import TextBlob
|
| 9 |
from src.inference import predict
|
| 10 |
+
from src.responses import get_response, correct_spelling, neg_inputs
|
| 11 |
|
| 12 |
+
st.title("🌿 EmotiBot")
|
| 13 |
+
user = st.text_input("You:")
|
| 14 |
+
if st.button("Send") and user:
|
| 15 |
+
txt = correct_spelling(user)
|
| 16 |
+
emo = 'sadness' if any(p in txt.lower() for p in neg_inputs) else predict(txt)
|
| 17 |
+
reply, done = get_response(emo, txt)
|
| 18 |
+
st.markdown(f"**Detected emotion:** {emo}")
|
| 19 |
+
st.write(reply)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if done:
|
| 21 |
+
st.write("Take care!")
|
|
|