Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import transformers
|
3 |
+
import torch
|
4 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
5 |
+
|
6 |
+
# Load tokenizer and model
|
7 |
+
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
|
8 |
+
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')
|
9 |
+
|
10 |
+
# Define a function to preprocess user input
|
11 |
+
def preprocess_input(text):
|
12 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
13 |
+
return encoded_input
|
14 |
+
|
15 |
+
# Define a function to generate response based on user input
|
16 |
+
def generate_response(user_input):
|
17 |
+
encoded_input = preprocess_input(user_input)
|
18 |
+
outputs = model(**encoded_input)
|
19 |
+
# Extract relevant information from model outputs (e.g., predicted class)
|
20 |
+
# Based on the extracted information, formulate a response using predefined responses or logic
|
21 |
+
response = "I'm still under development, but I understand you said: {}".format(user_input)
|
22 |
+
return response
|
23 |
+
|
24 |
+
# Start the chat loop
|
25 |
+
while True:
|
26 |
+
# Get user input
|
27 |
+
uinput = st.text_input("Enter your input: ")
|
28 |
+
|
29 |
+
if uinput.lower() == "quit":
|
30 |
+
break
|
31 |
+
|
32 |
+
|
33 |
+
# Generate response based on user input
|
34 |
+
|
35 |
+
bot_response = generate_response(line) # Assuming generate_response is defined elsewhere
|
36 |
+
print("Bot:", bot_response)
|