import streamlit as st from transformers import pipeline # Set up Streamlit title and description st.title("Sentiment Analysis, Audio Feedback, and Response Generation") st.write("Enter a review and get the sentiment analysis with audio feedback and a professional response.") # Load the sentiment analysis model sentiment_analysis = pipeline("text-classification", model="JACOBBBB/CustomModel_JL") # Load the text-to-speech model text_to_audio = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech") # Load the text generation model response_generator = pipeline("text-generation", model="gpt-2") # Text input for user to enter the review review = st.text_area("Enter the review to analyze", "") # Perform operations when the user clicks the "Analyze and Respond" button if st.button("Analyze and Respond"): # Perform sentiment analysis on the input review sentiment_result = sentiment_analysis(review)[0] label = sentiment_result['label'] score = sentiment_result['score'] # Display the sentiment analysis result st.write("Review:", review) st.write("Predicted Sentiment:", label) st.write("Confidence Score:", f"{score * 100:.2f}%") # Generate the response text response_text = f"The sentiment of the review is {label} with a confidence of {score * 100:.2f} percent." # Generate audio from response text audio = text_to_audio(response_text) st.audio(audio['audio'], format='audio/wav', sample_rate=audio['sampling_rate']) # Generate a professional response based on the review and its sentiment prompt = f"The guest has left a {label} review stating: '{review}'. How should the hotel management professionally respond?" professional_response = response_generator(prompt, max_length=150, num_return_sequences=1)[0]['generated_text'] # Display the generated professional response st.write("Generated Professional Response:", professional_response)