FinalProject / app.py
Thea231's picture
Update app.py
2022c97 verified
raw
history blame
1.31 kB
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}")