tarrasyed19472007 commited on
Commit
9274965
·
verified ·
1 Parent(s): fbe0002

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -60
app.py CHANGED
@@ -1,62 +1,17 @@
1
- import streamlit as st
2
  from transformers import pipeline
3
- from datasets import load_dataset
4
-
5
- # Load the pre-trained model for sentiment analysis (using a valid model from Hugging Face)
6
- emotion_analyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2")
7
-
8
- # Load a dataset from Hugging Face (Sentiment Analysis - SST-2)
9
- dataset = load_dataset("glue", "sst2")
10
-
11
- # Example of how to use a dataset (showing the first few examples)
12
- st.write("Dataset Sample (SST-2):")
13
- st.write(dataset["train"][0:3]) # Display the first 3 samples
14
-
15
- # Define the function to analyze emotions and suggest strategies
16
- def analyze_and_suggest(responses):
17
- suggestions = []
18
- for response in responses:
19
- # Get the sentiment analysis result
20
- result = emotion_analyzer(response)[0]
21
- label = result['label']
22
-
23
- # Suggest strategies based on sentiment
24
- if label == "NEGATIVE":
25
- suggestions.append("Try deep breathing exercises or mindfulness activities.")
26
- elif label == "POSITIVE":
27
- suggestions.append("Great! Keep the positivity going with a walk or some light exercise.")
28
- else:
29
- suggestions.append("Consider focusing on better sleep or reflecting on your priorities.")
30
-
31
- return suggestions
32
-
33
- # Streamlit App UI
34
- st.title("Personalized Self-Care Strategy App")
35
- st.markdown("### Answer the following questions to get personalized self-care suggestions.")
36
-
37
- # List of questions for user to answer
38
- questions = [
39
- "1. How do you feel about your overall health today?",
40
- "2. How have you been sleeping recently?",
41
- "3. Do you feel overwhelmed with tasks or emotions?",
42
- "4. What are your energy levels like today?",
43
- "5. How often do you exercise or engage in physical activity?"
44
- ]
45
-
46
- # Collect user responses
47
- responses = []
48
- for question in questions:
49
- responses.append(st.text_input(question, placeholder="Type your response here..."))
50
-
51
- # Button to analyze and provide self-care suggestions
52
- if st.button("Get Self-Care Suggestions"):
53
- if all(responses): # Ensure all questions are answered
54
- suggestions = analyze_and_suggest(responses)
55
- st.markdown("### **Your Personalized Suggestions**")
56
- for i, suggestion in enumerate(suggestions, 1):
57
- st.write(f"**{i}.** {suggestion}")
58
- else:
59
- st.error("Please answer all the questions before proceeding.")
60
-
61
- transformers-cli cache --clear
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ # Ensure you have the correct model name
4
+ model_name = "distilbert-base-uncased-finetuned-sst-2" # Change if needed (verify on Hugging Face model hub)
5
+
6
+ # Optionally, you can pass a token if the model is private or requires authentication
7
+ # Use your Hugging Face token here if needed (skip this part if the model is public)
8
+ token = "your_token_here" # Replace with your actual Hugging Face token if needed
9
+
10
+ # Initialize the emotion analyzer pipeline
11
+ try:
12
+ emotion_analyzer = pipeline("text-classification",
13
+ model=model_name,
14
+ use_auth_token=token if token else None)
15
+ print("Model loaded successfully!")
16
+ except Exception as e:
17
+ print(f"An error occurred: {e}")