Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis model
|
5 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Load the chatbot model
|
8 |
+
chatbot = pipeline("conversational")
|
9 |
+
|
10 |
+
# Define a function to generate responses from the chatbot
|
11 |
+
def generate_response(input_text):
|
12 |
+
# Get the sentiment of the input
|
13 |
+
sentiment = sentiment_analysis(input_text)[0]['label']
|
14 |
+
# Generate a response from the chatbot using the sentiment as context
|
15 |
+
response = chatbot(input_text, context=sentiment)[0]['generated_text']
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Create a title for the app
|
19 |
+
st.title("Sentiment-Aware Chatbot")
|
20 |
+
|
21 |
+
# Create a text input for the user to enter their message
|
22 |
+
user_input = st.text_input("Enter your message:")
|
23 |
+
|
24 |
+
# When the user submits their message, generate a response from the chatbot and display it
|
25 |
+
if st.button("Submit"):
|
26 |
+
response = generate_response(user_input)
|
27 |
+
st.write("Chatbot:", response)
|