File size: 1,822 Bytes
cda6f4a
d2fcec4
cda6f4a
d2fcec4
 
 
cda6f4a
 
 
 
 
d2fcec4
 
9b12195
 
 
5f8f43f
 
cda6f4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2fcec4
 
cda6f4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()