Spaces:
Sleeping
Sleeping
Nikhil0987
commited on
Commit
•
3a0dedc
1
Parent(s):
2e9675b
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,34 @@
|
|
1 |
-
import
|
2 |
-
import torch
|
3 |
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
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 |
-
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
4 |
|
5 |
+
# Title and Description
|
6 |
+
st.title("Simple DistilBERT Chatbot")
|
7 |
+
st.write("This is a basic chatbot prototype. Ask it something!")
|
8 |
+
|
9 |
+
# Load Model and Tokenizer
|
10 |
+
@st.cache_resource # Cache for efficiency
|
11 |
+
def load_model_tokenizer():
|
12 |
+
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
|
13 |
+
model = DistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')
|
14 |
+
return tokenizer, model
|
15 |
+
|
16 |
+
tokenizer, model = load_model_tokenizer()
|
17 |
+
|
18 |
+
# User Input
|
19 |
+
user_input = st.text_input("You: ")
|
20 |
+
|
21 |
+
# Generate Response on Button Click
|
22 |
+
if st.button("Send"):
|
23 |
+
if not user_input:
|
24 |
+
st.warning("Please enter some text.")
|
25 |
+
else:
|
26 |
+
# Preprocess and Generate Response (placeholder)
|
27 |
+
encoded_input = preprocess_input(user_input)
|
28 |
+
outputs = model(**encoded_input)
|
29 |
+
|
30 |
+
# (TODO) Extract relevant info from outputs
|
31 |
+
|
32 |
+
bot_response = "I'm still under development, but I understand you said: {}".format(user_input)
|
33 |
+
st.write("Bot: " + bot_response)
|
34 |
+
|