Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the Hugging Face pipelines
|
5 |
+
classifier = pipeline("text-classification", model="bhadresh-savani/bert-base-go-emotion")
|
6 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
7 |
+
|
8 |
+
# Streamlit app UI
|
9 |
+
st.title("Emotion Detection and Comment Summarization")
|
10 |
+
st.markdown(
|
11 |
+
"""
|
12 |
+
This app detects the emotion in a given comment and provides a concise summary.
|
13 |
+
"""
|
14 |
+
)
|
15 |
+
|
16 |
+
# Input text box for comments
|
17 |
+
comment_input = st.text_area(
|
18 |
+
"Enter your comment:",
|
19 |
+
placeholder="Type your comment here...",
|
20 |
+
height=200
|
21 |
+
)
|
22 |
+
|
23 |
+
# Analyze button
|
24 |
+
if st.button("Analyze Comment"):
|
25 |
+
if not comment_input.strip():
|
26 |
+
st.error("Please provide a valid comment.")
|
27 |
+
else:
|
28 |
+
# Perform emotion classification
|
29 |
+
emotion_result = classifier(comment_input)[0]
|
30 |
+
emotion_label = emotion_result["label"]
|
31 |
+
emotion_score = round(emotion_result["score"], 4)
|
32 |
+
|
33 |
+
# Perform summarization
|
34 |
+
summary_result = summarizer(comment_input, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
|
35 |
+
|
36 |
+
# Display results
|
37 |
+
st.subheader("Analysis Result")
|
38 |
+
st.write(f"### **Emotion:** {emotion_label} (Confidence: {emotion_score})")
|
39 |
+
st.write(f"### **Summary:** {summary_result}")
|