|
import streamlit as st |
|
import transformers |
|
import torch |
|
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification |
|
|
|
|
|
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased') |
|
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased') |
|
|
|
|
|
def preprocess_input(text): |
|
encoded_input = tokenizer(text, return_tensors='pt') |
|
return encoded_input |
|
|
|
|
|
def generate_response(user_input): |
|
encoded_input = preprocess_input(user_input) |
|
outputs = model(**encoded_input) |
|
|
|
|
|
response = "I'm still under development, but I understand you said: {}".format(user_input) |
|
return response |
|
|
|
st.title("Simple Sentiment Chatbot") |
|
user_input = st.text_input("Enter your message:") |
|
|
|
|
|
if user_input: |
|
if user_input.lower() == "quit": |
|
st.stop() |
|
|
|
|
|
|
|
|
|
bot_response = generate_response(user_input) |
|
print(bot_response) |