Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
|
|
|
| 3 |
def main():
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
st.write(f"Sentiment: {sentiment}")
|
| 14 |
-
st.write(f"Confidence: {confidence:.2f}")
|
| 15 |
if __name__ == "__main__":
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
+
|
| 4 |
def main():
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
model_name = "microsoft/resnet-50"
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Initialize the pipeline
|
| 11 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 12 |
+
|
| 13 |
+
st.title("Sentiment Analysis with HuggingFace Spaces")
|
| 14 |
+
st.write("Enter a sentence to analyze its sentiment:")
|
| 15 |
+
|
| 16 |
+
user_input = st.text_input("")
|
| 17 |
+
if user_input:
|
| 18 |
+
result = sentiment_pipeline(user_input)
|
| 19 |
+
sentiment = result["label"]
|
| 20 |
+
confidence = result["score"]
|
| 21 |
+
|
| 22 |
+
st.write(f"Sentiment: {sentiment}")
|
| 23 |
+
st.write(f"Confidence: {confidence:.2f}")
|
| 24 |
|
|
|
|
|
|
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
main()
|
| 27 |
+
|
| 28 |
|
| 29 |
|