|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
emotion_classifier = pipeline("text-classification", model="bhadresh-savani/bert-base-go-emotion") |
|
|
feedback_generator = pipeline("text2text-generation", model="facebook/blenderbot-3B") |
|
|
text_to_audio = pipeline("text-to-speech", model="facebook/mms-tts-eng") |
|
|
|
|
|
|
|
|
st.title("Emotion Detection and Feedback Generation") |
|
|
st.markdown(""" |
|
|
This app detects emotions in a given comment, generates appropriate feedback, and reads it aloud. |
|
|
""") |
|
|
|
|
|
|
|
|
comment_input = st.text_area("Enter your comment:", placeholder="Type your comment here...", height=200) |
|
|
|
|
|
|
|
|
if st.button("Analyze Comment"): |
|
|
if not comment_input.strip(): |
|
|
st.error("Please provide a valid comment.") |
|
|
else: |
|
|
|
|
|
emotion_result = emotion_classifier(comment_input)[0] |
|
|
emotion_label = emotion_result["label"] |
|
|
emotion_score = round(emotion_result["score"], 4) |
|
|
|
|
|
|
|
|
feedback = feedback_generator(f"emotion: {emotion_label} text: {comment_input}", max_length=50)[0]["generated_text"] |
|
|
|
|
|
|
|
|
st.text('Generating audio data...') |
|
|
audio_data = text_to_audio(feedback) |
|
|
|
|
|
|
|
|
|
|
|
st.subheader("Analysis Result") |
|
|
st.write(f"### **Emotion:** {emotion_label} (Confidence: {emotion_score})") |
|
|
st.write(f"### **Generated Feedback:** {feedback}") |
|
|
|
|
|
|
|
|
|
|
|
if st.button("Play Audio"): |
|
|
st.audio(audio_data['audio'], |
|
|
format="audio/wav", |
|
|
start_time=0, |
|
|
sample_rate = audio_data['sampling_rate']) |