File size: 2,001 Bytes
4b4677d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
from transformers import pipeline

classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)


st.set_page_config(
    page_title="Emotion Detection",
    page_icon=":bar_chart:",
    layout="centered",  
)


st.markdown(
    """
    <style>
    .stButton > button {
        background-color: #4CAF50;
        color: white;
        font-size: 18px;
        padding: 10px 20px;
        border: none;
        cursor: pointer;
    }
    .stButton > button:hover {
        background-color: #86D8DB;
    }
    .stApp {
        background-color: #73D9C8;  /* Background color */
    }
    </style>
    """,
    unsafe_allow_html=True,
)


st.title("🎭 Emotion Detection")
st.markdown("Choose the input type and enter a sentence or upload an image to classify emotions.")


input_type = st.radio("Select Input Type", ("Text", "Image"))


if input_type == "Text":
    user_input = st.text_area("Enter a sentence:")
    uploaded_image = None
else:
    uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
    user_input = ""


if st.button("Analyze"):
    with st.spinner("Analyzing..."):
        if input_type == "Text" and user_input:
      
            model_outputs = classifier(user_input)
            st.subheader("Emotion Classification Results (Text):")
        elif input_type == "Image" and uploaded_image is not None:
            
            st.image(uploaded_image, use_column_width=True, caption="Uploaded Image")
            model_outputs = classifier("Analyze this image.")
            st.subheader("Emotion Classification Results (Image):")
        else:
            st.warning("Please enter a sentence or upload an image to analyze.")

        for label_info in model_outputs[0]:
            label = label_info["label"]
            score = label_info["score"]
            st.write(f"- {label}: {score:.4f}")


    if st.button("Clear"):
        user_input = ""
        uploaded_image = None