Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
import numpy as np
|
4 |
|
5 |
# Set up Streamlit title and description
|
6 |
-
st.title("Sentiment Analysis and
|
7 |
-
st.write("Enter a review and get the sentiment analysis with audio feedback.")
|
8 |
|
9 |
# Load the sentiment analysis model
|
10 |
sentiment_analysis = pipeline("text-classification", model="JACOBBBB/CustomModel_JL")
|
11 |
|
12 |
# Load the text-to-speech model
|
13 |
-
text_to_audio = pipeline("text-to-
|
|
|
|
|
|
|
14 |
|
15 |
# Text input for user to enter the review
|
16 |
review = st.text_area("Enter the review to analyze", "")
|
17 |
|
18 |
-
# Perform
|
19 |
-
if st.button("Analyze"):
|
20 |
# Perform sentiment analysis on the input review
|
21 |
sentiment_result = sentiment_analysis(review)[0]
|
22 |
label = sentiment_result['label']
|
23 |
-
score = sentiment_result['score']
|
24 |
|
25 |
# Display the sentiment analysis result
|
26 |
st.write("Review:", review)
|
@@ -32,7 +34,11 @@ if st.button("Analyze"):
|
|
32 |
|
33 |
# Generate audio from response text
|
34 |
audio = text_to_audio(response_text)
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
# Display the
|
37 |
-
|
38 |
-
st.audio(audio['audio'], format='audio/wav', sample_rate=audio['sampling_rate'])
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Set up Streamlit title and description
|
5 |
+
st.title("Sentiment Analysis, Audio Feedback, and Response Generation")
|
6 |
+
st.write("Enter a review and get the sentiment analysis with audio feedback and a professional response.")
|
7 |
|
8 |
# Load the sentiment analysis model
|
9 |
sentiment_analysis = pipeline("text-classification", model="JACOBBBB/CustomModel_JL")
|
10 |
|
11 |
# Load the text-to-speech model
|
12 |
+
text_to_audio = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
|
13 |
+
|
14 |
+
# Load the text generation model
|
15 |
+
response_generator = pipeline("text-generation", model="gpt-2")
|
16 |
|
17 |
# Text input for user to enter the review
|
18 |
review = st.text_area("Enter the review to analyze", "")
|
19 |
|
20 |
+
# Perform operations when the user clicks the "Analyze and Respond" button
|
21 |
+
if st.button("Analyze and Respond"):
|
22 |
# Perform sentiment analysis on the input review
|
23 |
sentiment_result = sentiment_analysis(review)[0]
|
24 |
label = sentiment_result['label']
|
25 |
+
score = sentiment_result['score']
|
26 |
|
27 |
# Display the sentiment analysis result
|
28 |
st.write("Review:", review)
|
|
|
34 |
|
35 |
# Generate audio from response text
|
36 |
audio = text_to_audio(response_text)
|
37 |
+
st.audio(audio['audio'], format='audio/wav', sample_rate=audio['sampling_rate'])
|
38 |
+
|
39 |
+
# Generate a professional response based on the review and its sentiment
|
40 |
+
prompt = f"The guest has left a {label} review stating: '{review}'. How should the hotel management professionally respond?"
|
41 |
+
professional_response = response_generator(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
|
42 |
|
43 |
+
# Display the generated professional response
|
44 |
+
st.write("Generated Professional Response:", professional_response)
|
|