File size: 1,309 Bytes
ac58aab
 
 
7940be9
ac58aab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2022c97
ac58aab
 
 
 
0128a52
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
import streamlit as st
from transformers import pipeline


# Load the Hugging Face pipelines
classifier = pipeline("text-classification", model="bhadresh-savani/bert-base-go-emotion")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Streamlit app UI
st.title("Emotion Detection and Comment Summarization")
st.markdown(
    """
    This app detects the emotion in a given comment and provides a concise summary.
    """
)

# Input text box for comments
comment_input = st.text_area(
    "Enter your comment:",
    placeholder="Type your comment here...",
    height=200
)

# Analyze button
if st.button("Analyze Comment"):
    if not comment_input.strip():
        st.error("Please provide a valid comment.")
    else:
        # Perform emotion classification
        emotion_result = classifier(comment_input)[0]
        emotion_label = emotion_result["label"]
        emotion_score = round(emotion_result["score"], 4)

        # Perform summarization
        summary_result = summarizer(comment_input, max_length=30, min_length=10, do_sample=False)[0]["summary_text"]

        # Display results
        st.subheader("Analysis Result")
        st.write(f"### **Emotion:** {emotion_label} (Confidence: {emotion_score})")
        st.write(f"### **Comment Summary:** {summary_result}")