File size: 1,291 Bytes
24f121d
31c316e
76be9d9
31c316e
360e70e
31c316e
 
 
72e95a8
31c316e
 
 
 
5d551ae
31c316e
 
 
 
 
 
 
 
5d551ae
01890f8
 
2e9675b
01890f8
 
 
 
2e9675b
fec81aa
2e9675b
15a0183
 
31c316e
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
29
30
31
32
33
34
35
36
37
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)