Tryfonas commited on
Commit
8d6519f
Β·
verified Β·
1 Parent(s): c78f488

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,22 +1,27 @@
1
  import streamlit as st
2
- # from setfit import SetFitModel
3
 
4
- # Cache the model loading process to optimize performance on Hugging Face Spaces
5
- # @st.cache_resource
6
- # def load_model():
7
- # return SetFitModel.from_pretrained("Tryfonas/setfit-paraphrase-mpnet-base-v2-sst2")
8
 
9
- # model = load_model()
 
 
 
 
10
 
11
  st.title("Text Sentiment Analysis 😊😞")
12
 
13
- # Create a text input for a single sentence
14
  user_input = st.text_input("Enter a sentence for sentiment analysis:", placeholder="I love this!")
15
 
16
- # Add a button to trigger predictions
17
  if st.button("Analyze Sentiment"):
18
  if user_input:
19
- # Temporarily show the input instead of model predictions
20
- st.write(f"Prediction for '{user_input}': This is a placeholder response.")
 
 
 
21
  else:
22
  st.write("Please enter a sentence to analyze.")
 
1
  import streamlit as st
2
+ from setfit import SetFitModel
3
 
4
+ @st.cache_resource
5
+ def load_model():
6
+ st.write("Loading model...")
7
+ return SetFitModel.from_pretrained("Tryfonas/setfit-paraphrase-mpnet-base-v2-sst2")
8
 
9
+ try:
10
+ model = load_model()
11
+ st.write("Model loaded successfully!")
12
+ except Exception as e:
13
+ st.error(f"Failed to load model: {e}")
14
 
15
  st.title("Text Sentiment Analysis 😊😞")
16
 
 
17
  user_input = st.text_input("Enter a sentence for sentiment analysis:", placeholder="I love this!")
18
 
 
19
  if st.button("Analyze Sentiment"):
20
  if user_input:
21
+ try:
22
+ predictions = model([user_input])
23
+ st.write(f"Prediction for '{user_input}': {predictions[0]}")
24
+ except Exception as e:
25
+ st.error(f"Error during prediction: {e}")
26
  else:
27
  st.write("Please enter a sentence to analyze.")