File size: 940 Bytes
fc7f2a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Load the sentiment analysis model
sentiment_analysis = pipeline("sentiment-analysis")

# Load the chatbot model
chatbot = pipeline("conversational")

# Define a function to generate responses from the chatbot
def generate_response(input_text):
    # Get the sentiment of the input
    sentiment = sentiment_analysis(input_text)[0]['label']
    # Generate a response from the chatbot using the sentiment as context
    response = chatbot(input_text, context=sentiment)[0]['generated_text']
    return response

# Create a title for the app
st.title("Sentiment-Aware Chatbot")

# Create a text input for the user to enter their message
user_input = st.text_input("Enter your message:")

# When the user submits their message, generate a response from the chatbot and display it
if st.button("Submit"):
    response = generate_response(user_input)
    st.write("Chatbot:", response)