awacke1's picture
Create app.py
fc7f2a5
raw
history blame contribute delete
No virus
940 Bytes
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)