Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
classifier = pipeline("text-classification", model="rxh1/Finetune_2")
|
5 |
+
text2text = pipeline("text2text-generation", model="facebook/blenderbot_small-90M")
|
6 |
+
# Streamlit application title
|
7 |
+
st.title("Text Sentiment Classification and Response Generation")
|
8 |
+
st.write("Create auto reply for three sentiment: positive, neutral, negative")
|
9 |
+
|
10 |
+
# Text input for user to enter the text to classify
|
11 |
+
text = st.text_area("Enter the text to reply", "")
|
12 |
+
|
13 |
+
# Perform text classification when the user clicks the "Classify" button
|
14 |
+
if st.button("Reply"):
|
15 |
+
# Perform text classification on the input text
|
16 |
+
result = classifier(text)[0]
|
17 |
+
|
18 |
+
# Display the classification result
|
19 |
+
prediction = result['label']
|
20 |
+
st.write("Text:", text)
|
21 |
+
st.write("Sentiment:", prediction)
|
22 |
+
|
23 |
+
# Generate a response based on the classification result
|
24 |
+
if prediction == "negative":
|
25 |
+
answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is bad.")[0]["generated_text"]
|
26 |
+
elif prediction == "neutral":
|
27 |
+
answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is peaceful.")[0]["generated_text"]
|
28 |
+
else:
|
29 |
+
answer = text2text(f"You are the owner of Starbucks and I am the customer and my feeling sentiment is good.")[0]["generated_text"]
|
30 |
+
|
31 |
+
st.write("Response:", answer)
|