Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
def summarize_text(text):
|
| 5 |
-
unmasker = pipeline("
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def main():
|
| 10 |
user_input = st.text_area("Input Text Here")
|
| 11 |
-
if st.button("
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|
| 17 |
-
main()
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
+
import altair as alt
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
def summarize_text(text):
|
| 7 |
+
unmasker = pipeline("sentiment-analysis", model="stevhliu/my_awesome_model")
|
| 8 |
+
sentiment_output = unmasker(text)[0]
|
| 9 |
+
sentiment_label = sentiment_output["label"]
|
| 10 |
+
sentiment_score = sentiment_output["score"]
|
| 11 |
+
return sentiment_label, sentiment_score
|
| 12 |
|
| 13 |
def main():
|
| 14 |
user_input = st.text_area("Input Text Here")
|
| 15 |
+
if st.button("Analyze Sentiment"):
|
| 16 |
+
sentiment_label, sentiment_score = summarize_text(user_input)
|
| 17 |
+
if sentiment_label == "LABEL_1":
|
| 18 |
+
sentiment_label = "Positive"
|
| 19 |
+
pos_score = sentiment_score
|
| 20 |
+
neg_score = 1 - sentiment_score
|
| 21 |
+
else:
|
| 22 |
+
sentiment_label = "Negative"
|
| 23 |
+
neg_score = sentiment_score
|
| 24 |
+
pos_score = 1 - sentiment_score
|
| 25 |
+
|
| 26 |
+
st.write(f"Sentiment Label: {sentiment_label}")
|
| 27 |
+
st.write(f"Positive Score: {pos_score:.2f}")
|
| 28 |
+
st.write(f"Negative Score: {neg_score:.2f}")
|
| 29 |
+
|
| 30 |
+
chart_data = pd.DataFrame({"Sentiment Score": [pos_score, neg_score]}, index=["Positive", "Negative"])
|
| 31 |
+
|
| 32 |
+
chart = alt.Chart(chart_data.reset_index()).mark_bar().encode(
|
| 33 |
+
x=alt.X('index:N', title=None),
|
| 34 |
+
y=alt.Y('Sentiment Score:Q', title="Sentiment Score"),
|
| 35 |
+
color=alt.Color('index:N', scale=alt.Scale(domain=['Positive', 'Negative'], range=['green', 'red']), legend=None)
|
| 36 |
+
).properties(
|
| 37 |
+
width=300,
|
| 38 |
+
height=200
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
st.altair_chart(chart, use_container_width=True)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
+
main()
|