Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import transformers | |
| import torch | |
| from transformers import DistilBertTokenizer, DistilBertForSequenceClassification | |
| # Load tokenizer and model | |
| tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased') | |
| model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased') | |
| # Define a function to preprocess user input | |
| def preprocess_input(text): | |
| encoded_input = tokenizer(text, return_tensors='pt') | |
| return encoded_input | |
| # Define a function to generate response based on user input | |
| def generate_response(user_input): | |
| encoded_input = preprocess_input(user_input) | |
| outputs = model(**encoded_input) | |
| # Extract relevant information from model outputs (e.g., predicted class) | |
| # Based on the extracted information, formulate a response using predefined responses or logic | |
| 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:") | |
| # Preprocess and generate response when the user hits Enter | |
| if user_input: | |
| if user_input.lower() == "quit": | |
| st.stop() | |
| # Generate response based on user input | |
| bot_response = generate_response(uinput) | |
| print("Bot:", bot_response) | |