File size: 1,407 Bytes
65625b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import streamlit as st

classifier = pipeline("text-classification", model="rxh1/Finetune_2")
text2text = pipeline("text2text-generation", model="facebook/blenderbot_small-90M")
# Streamlit application title
st.title("Text Sentiment Classification and Response Generation")
st.write("Create auto reply for three sentiment: positive, neutral, negative")

# Text input for user to enter the text to classify
text = st.text_area("Enter the text to reply", "")

# Perform text classification when the user clicks the "Classify" button
if st.button("Reply"):
    # Perform text classification on the input text
    result = classifier(text)[0]

    # Display the classification result
    prediction = result['label']
    st.write("Text:", text)
    st.write("Sentiment:", prediction)

    # Generate a response based on the classification result
    if prediction == "negative":
        answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is bad.")[0]["generated_text"]
    elif prediction == "neutral":
        answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is peaceful.")[0]["generated_text"]
    else:
        answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is good.")[0]["generated_text"]

    st.write("Response:", answer)