Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
-
from transformers import pipeline
|
| 5 |
|
| 6 |
def main():
|
| 7 |
st.set_page_config(page_title="Sentiment Analysis App")
|
|
@@ -12,8 +12,10 @@ def main():
|
|
| 12 |
|
| 13 |
if st.button("Analyze"):
|
| 14 |
if text_input:
|
|
|
|
|
|
|
| 15 |
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
|
| 16 |
-
result = sentiment_classifier(
|
| 17 |
st.write(f"Sentiment: {result['label']}")
|
| 18 |
st.write(f"Score: {round(result['score'], 4)}")
|
| 19 |
|
|
@@ -21,7 +23,7 @@ def main():
|
|
| 21 |
df_sentiments = pd.DataFrame({"sentiment": ["Positive", "Negative", "Neutral"], "count": [0, 0, 0]})
|
| 22 |
|
| 23 |
# get the sentiment distribution of the text using the selected model
|
| 24 |
-
results = sentiment_classifier(
|
| 25 |
for r in results:
|
| 26 |
if r["label"] == "POSITIVE":
|
| 27 |
df_sentiments.loc[0, "count"] = r["score"]
|
|
@@ -38,4 +40,4 @@ def main():
|
|
| 38 |
st.warning("Please enter some text for sentiment analysis")
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
+
from transformers import pipeline, AutoTokenizer
|
| 5 |
|
| 6 |
def main():
|
| 7 |
st.set_page_config(page_title="Sentiment Analysis App")
|
|
|
|
| 12 |
|
| 13 |
if st.button("Analyze"):
|
| 14 |
if text_input:
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
+
encoded_input = tokenizer(text_input, return_tensors='pt', padding=True, truncation=True)
|
| 17 |
sentiment_classifier = pipeline("sentiment-analysis", model=model_name)
|
| 18 |
+
result = sentiment_classifier(encoded_input)[0]
|
| 19 |
st.write(f"Sentiment: {result['label']}")
|
| 20 |
st.write(f"Score: {round(result['score'], 4)}")
|
| 21 |
|
|
|
|
| 23 |
df_sentiments = pd.DataFrame({"sentiment": ["Positive", "Negative", "Neutral"], "count": [0, 0, 0]})
|
| 24 |
|
| 25 |
# get the sentiment distribution of the text using the selected model
|
| 26 |
+
results = sentiment_classifier(encoded_input)
|
| 27 |
for r in results:
|
| 28 |
if r["label"] == "POSITIVE":
|
| 29 |
df_sentiments.loc[0, "count"] = r["score"]
|
|
|
|
| 40 |
st.warning("Please enter some text for sentiment analysis")
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
+
main()
|