File size: 1,078 Bytes
e72169b
 
 
 
 
 
 
 
 
b611c2e
e72169b
 
 
 
 
 
 
 
1cf4b9a
 
 
fc91a69
e72169b
 
fc91a69
e72169b
 
 
 
 
 
 
 
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
import streamlit as st

from config import settings
from utils import init_model, custom_predict


def main():
    st.title("Crypto Market Sentiment Analyzer")

    raw_text = st.text_area("Enter Text Here", "Type Here, for example - The cryptocurrency market is down today due to Trump's latest restrictions on Nvidia")

    if st.button("Analyze"):
        pipe = init_model(settings.TASK, settings.MODEL_NAME)
        result = custom_predict(raw_text, pipe)

        label = result[0]["label"]
        score = result[0]["score"]

        # Crypto market is Positive (LABEL_1) or Negative (LABEL_0)
        color = "green" if label == "LABEL_1" else "red"
        emoji = "😊" if label == "LABEL_1" else "😡"
        type = "positive" if label == "LABEL_1" else "negative"

        st.markdown(
            f"<h3 style='color:{color};'>Sentiment: {type} {emoji} ({score:.1%})</h3>",
            unsafe_allow_html=True,
        )
        st.progress(score)  # score от 0.0 до 1.0
        st.write(f"Confidence: **{score:.1%}**")


if __name__ == "__main__":
    main()