Spaces:
Runtime error
Runtime error
import pandas as pd | |
import streamlit as st | |
import altair as alt | |
from transformers import pipeline | |
def summarize_text(text): | |
unmasker = pipeline("sentiment-analysis", model="stevhliu/my_awesome_model") | |
sentiment_output = unmasker(text)[0] | |
sentiment_label = sentiment_output["label"] | |
sentiment_score = sentiment_output["score"] | |
return sentiment_label, sentiment_score | |
def main(): | |
st.markdown( | |
"<center><h1>🤪Human moderator😡</h1>", | |
unsafe_allow_html=True) | |
st.image("https://huggingface.co/spaces/kushan98/comment_review/resolve/main/cs_img.jpg") | |
user_input = st.text_area("Input your Sentiment") | |
if st.button("Analyze Sentiment"): | |
sentiment_label, sentiment_score = summarize_text(user_input) | |
if sentiment_label == "LABEL_1": | |
sentiment_label = "Positive" | |
pos_score = sentiment_score | |
neg_score = 1 - sentiment_score | |
else: | |
sentiment_label = "Negative" | |
neg_score = sentiment_score | |
pos_score = 1 - sentiment_score | |
st.write(f"Sentiment Label: {sentiment_label}") | |
st.write(f"Positive Score: {pos_score:.2f}") | |
st.write(f"Negative Score: {neg_score:.2f}") | |
chart_data = pd.DataFrame({"Sentiment Score": [pos_score, neg_score]}, index=["Positive", "Negative"]) | |
chart = alt.Chart(chart_data.reset_index()).mark_bar().encode( | |
x=alt.X('index:N', title=None), | |
y=alt.Y('Sentiment Score:Q', title="Sentiment Score"), | |
color=alt.Color('index:N', scale=alt.Scale(domain=['Positive', 'Negative'], range=['green', 'red']), legend=None) | |
).properties( | |
width=300, | |
height=200 | |
) | |
st.altair_chart(chart, use_container_width=True) | |
if __name__ == "__main__": | |
main() | |