tarrasyed19472007 commited on
Commit
1985126
Β·
verified Β·
1 Parent(s): 6325706

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
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("🌺 Emotion Prediction App 🌈")
16
- st.subheader("Aloha! Enter your thoughts and let me predict your emotions. πŸ§ πŸ’‘")
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 public model for emotion classification
33
- model = pipeline(
34
  "text-classification",
35
  model="bhadresh-savani/distilbert-base-uncased-emotion",
36
- device=0 if torch.cuda.is_available() else -1, # Automatically use GPU if available
37
  )
38
  st.success("βœ… Model loaded successfully!")
39
- return model
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("### 🌟 Let's Get Started!")
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"#### 🧐 Question {i}: {question}")
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 with πŸ€— Transformers by OpenAI**
99
- Designed for an intuitive and aesthetic experience. 🌺
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
  )