opinder2906 commited on
Commit
b1bca3c
·
verified ·
1 Parent(s): 6f1ce68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -1,28 +1,21 @@
1
- # app.py
 
 
 
2
 
 
 
3
  from textblob import TextBlob
4
  from src.inference import predict
5
- from src.responses import get_response
6
 
7
- print("EmotiBot 🌿: Hi! How are you feeling today? (Type 'exit' to quit)")
8
-
9
- while True:
10
- user = input("You: ").strip()
11
- if user.lower() in ['exit','quit']:
12
- print("EmotiBot 🌿: Take care! I’m here whenever you want to talk.")
13
- break
14
- # optional spelling fix:
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
- break
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!")