Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
-
import time
|
| 5 |
|
| 6 |
# ---- Page Configuration ----
|
| 7 |
st.set_page_config(
|
|
@@ -12,31 +11,22 @@ st.set_page_config(
|
|
| 12 |
)
|
| 13 |
|
| 14 |
# ---- App Title ----
|
| 15 |
-
st.title("
|
| 16 |
-
st.subheader("
|
| 17 |
-
|
| 18 |
-
# ---- Background Information ----
|
| 19 |
-
st.markdown(
|
| 20 |
-
"""
|
| 21 |
-
Welcome to the Emotion Prediction App!
|
| 22 |
-
This tool uses a state-of-the-art natural language processing (NLP) model to analyze your responses and predict your emotions.
|
| 23 |
-
Perfect for everyone in Hawaii or anywhere looking for a simple, fun way to understand feelings better! π΄β¨
|
| 24 |
-
"""
|
| 25 |
-
)
|
| 26 |
|
| 27 |
# ---- Function to Load Emotion Analysis Model ----
|
| 28 |
@st.cache_resource
|
| 29 |
def load_emotion_model():
|
| 30 |
try:
|
| 31 |
st.info("β³ Loading the emotion analysis model, please wait...")
|
| 32 |
-
# Using a
|
| 33 |
-
|
| 34 |
"text-classification",
|
| 35 |
model="bhadresh-savani/distilbert-base-uncased-emotion",
|
| 36 |
-
device=0 if torch.cuda.is_available() else -1, #
|
| 37 |
)
|
| 38 |
st.success("β
Model loaded successfully!")
|
| 39 |
-
return
|
| 40 |
except Exception as e:
|
| 41 |
st.error(f"β οΈ Error loading model: {e}")
|
| 42 |
return None
|
|
@@ -57,8 +47,7 @@ def predict_emotion(text):
|
|
| 57 |
return {"Error": f"Prediction failed: {e}"}
|
| 58 |
|
| 59 |
# ---- User Input Section ----
|
| 60 |
-
st.write("###
|
| 61 |
-
|
| 62 |
questions = [
|
| 63 |
"How are you feeling today?",
|
| 64 |
"Describe your mood in a few words.",
|
|
@@ -71,7 +60,7 @@ responses = {}
|
|
| 71 |
|
| 72 |
# ---- Ask Questions and Analyze Responses ----
|
| 73 |
for i, question in enumerate(questions, start=1):
|
| 74 |
-
st.write(f"####
|
| 75 |
user_response = st.text_input(f"Your answer to Q{i}:", key=f"q{i}")
|
| 76 |
|
| 77 |
if user_response:
|
|
@@ -95,7 +84,7 @@ if st.button("Submit Responses"):
|
|
| 95 |
st.markdown(
|
| 96 |
"""
|
| 97 |
---
|
| 98 |
-
**Developed
|
| 99 |
-
Designed for
|
| 100 |
"""
|
| 101 |
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
# ---- Page Configuration ----
|
| 6 |
st.set_page_config(
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
# ---- App Title ----
|
| 14 |
+
st.title("π Emotion Prediction App π")
|
| 15 |
+
st.subheader("Understand your emotions better with AI-powered predictions!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# ---- Function to Load Emotion Analysis Model ----
|
| 18 |
@st.cache_resource
|
| 19 |
def load_emotion_model():
|
| 20 |
try:
|
| 21 |
st.info("β³ Loading the emotion analysis model, please wait...")
|
| 22 |
+
# Using a publicly available model
|
| 23 |
+
emotion_analyzer = pipeline(
|
| 24 |
"text-classification",
|
| 25 |
model="bhadresh-savani/distilbert-base-uncased-emotion",
|
| 26 |
+
device=0 if torch.cuda.is_available() else -1, # Use GPU if available
|
| 27 |
)
|
| 28 |
st.success("β
Model loaded successfully!")
|
| 29 |
+
return emotion_analyzer
|
| 30 |
except Exception as e:
|
| 31 |
st.error(f"β οΈ Error loading model: {e}")
|
| 32 |
return None
|
|
|
|
| 47 |
return {"Error": f"Prediction failed: {e}"}
|
| 48 |
|
| 49 |
# ---- User Input Section ----
|
| 50 |
+
st.write("### πΊ Let's Get Started!")
|
|
|
|
| 51 |
questions = [
|
| 52 |
"How are you feeling today?",
|
| 53 |
"Describe your mood in a few words.",
|
|
|
|
| 60 |
|
| 61 |
# ---- Ask Questions and Analyze Responses ----
|
| 62 |
for i, question in enumerate(questions, start=1):
|
| 63 |
+
st.write(f"#### β Question {i}: {question}")
|
| 64 |
user_response = st.text_input(f"Your answer to Q{i}:", key=f"q{i}")
|
| 65 |
|
| 66 |
if user_response:
|
|
|
|
| 84 |
st.markdown(
|
| 85 |
"""
|
| 86 |
---
|
| 87 |
+
**Developed using π€ Transformers**
|
| 88 |
+
Designed for a fun and intuitive experience! π
|
| 89 |
"""
|
| 90 |
)
|