File size: 3,832 Bytes
a765dc9
a6d379a
0cd0ca5
a765dc9
 
02a6b64
 
00df7a5
 
 
 
c8eecaa
7864b61
a852746
 
68f1809
00df7a5
a765dc9
 
 
7fb0b21
 
 
a852746
02a6b64
a765dc9
 
7fb0b21
a852746
7fb0b21
 
 
 
5e89a77
f617e67
 
 
7fb0b21
f617e67
7fb0b21
 
 
 
 
194e320
 
7fb0b21
 
f617e67
 
 
 
 
7fb0b21
b458d2a
7fb0b21
b458d2a
f91fe82
7fb0b21
a828f5d
7fb0b21
a852746
f617e67
 
 
925de67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
from transformers import pipeline
from datetime import datetime

# Set up Streamlit title and description
st.title("Sentiment Analysis , Audio Feedback, and Response Generation")
st.write("Enter a review, guess its sentiment (positive/negative), and get audio feedback on your guess and improve your Enlish.")

# 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-audio", model="vbrydik/mms-tts-eng-finetune-v3-train")

# Load the text generation model
response_generator = pipeline("text-generation", model="openai-community/gpt2")

# Text input for user to enter the review
review = st.text_area("Enter the review to analyze", "")

# Dropdown for user to guess the sentiment
user_guess = st.selectbox("Guess the sentiment of your review:", ("Positive", "Negative"))

# Perform operations when the user clicks the "Analyze and Respond" button
if st.button("Analyze and Generate"):
    # Perform sentiment analysis on the input review
    sentiment_result = sentiment_analysis(review)[0]
    label = sentiment_result['label'].upper()
    score = sentiment_result['score']
    
    # Check user's guess against the analysis
    guess_is_correct = (user_guess.upper() == label)
    guess_feedback = "Right" if guess_is_correct else "Wrong"
    if guess_feedback == "Right":
        feedback_text = f"Congratulations! Your guess was {guess_feedback}! The actual sentiment of the review is {label}."
    else:
        feedback_text = f"Sorry! Your guess was {guess_feedback}! The actual sentiment of the review is {label}."

    
    # Generate audio feedback for the guess
    feedback_audio = text_to_audio(feedback_text)
    st.audio(feedback_audio['audio'], format='audio/wav', sample_rate=feedback_audio['sampling_rate'])
    
    # Display the sentiment analysis result and feedback
    st.write("Predicted Sentiment:", label)
    st.write("Confidence Score:", f"{score * 100:.2f}%")
    st.write(feedback_text)

    # Generate audio of the review
    st.write("Audio of the review for practice your listening")
    review_audio = text_to_audio(f"Audio of the review for practice your listening: {review}")
    st.audio(review_audio['audio'], format='audio/wav', sample_rate=review_audio['sampling_rate'])

    # Generate a professional response based on the review and its sentiment
    if label == "POSITIVE":
        prompt = "Thank you for sharing your experience and choosing our hotel. We are glad that you had a wonderful stay with us."
    else:
        prompt = "Thank you for letting us know about the issues that you experienced during your recent stay at our hotel. Sorry for any inconvenience caused."

    professional_response = response_generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
    
    # Display the generated professional response
    st.write("Generated Professional Response:", professional_response)


st.title('Monthly Best Response Competition')
# Simple form for input using Streamlit
with st.form("user_input_form"):
    user_input = st.text_input("Enter your response:")
    submit_button = st.form_submit_button("Submit")

    if submit_button:
        # Current time when the input is received
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        # Format the entry to be saved
        entry = f"{current_time}: {user_input}\n"
        # Save the input to a local file
        with open("monthly_competition_entries.txt", "a") as file:
            file.write(entry)
        st.success("Your response has been saved and entered into the competition!")

# Display outside the form context
st.write("Feel free to submit more responses. Each unique response counts as a separate entry.")