Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,14 +13,28 @@ basic_model_url = "https://huggingface.co/anshupatel4298/bert-chatbot-model/reso
|
|
13 |
local_model_path = "basic_chatbot_model.h5"
|
14 |
bert_model_name = "anshupatel4298/bert-chatbot-model/bert_model"
|
15 |
|
16 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
if not os.path.exists(local_model_path):
|
18 |
response = requests.get(basic_model_url)
|
19 |
with open(local_model_path, 'wb') as f:
|
20 |
f.write(response.content)
|
21 |
|
22 |
-
# Load
|
23 |
-
basic_model
|
24 |
|
25 |
# Load BERT Model and Tokenizer
|
26 |
bert_model = TFBertForSequenceClassification.from_pretrained(bert_model_name)
|
@@ -51,3 +65,4 @@ if st.button("Send"):
|
|
51 |
response = tf.argmax(outputs.logits, axis=-1).numpy()[0]
|
52 |
|
53 |
st.write(f"Bot: {response}")
|
|
|
|
13 |
local_model_path = "basic_chatbot_model.h5"
|
14 |
bert_model_name = "anshupatel4298/bert-chatbot-model/bert_model"
|
15 |
|
16 |
+
# Define the model architecture
|
17 |
+
def create_model():
|
18 |
+
model = tf.keras.Sequential([
|
19 |
+
tf.keras.layers.Dense(128, activation='relu', input_shape=(100,)), # Adjust input shape accordingly
|
20 |
+
tf.keras.layers.Dropout(0.5),
|
21 |
+
tf.keras.layers.Dense(64, activation='relu'),
|
22 |
+
tf.keras.layers.Dropout(0.5),
|
23 |
+
tf.keras.layers.Dense(10, activation='softmax') # Adjust the number of classes accordingly
|
24 |
+
])
|
25 |
+
return model
|
26 |
+
|
27 |
+
# Create the model
|
28 |
+
basic_model = create_model()
|
29 |
+
|
30 |
+
# Download the Basic Model weights from the URL if not already downloaded
|
31 |
if not os.path.exists(local_model_path):
|
32 |
response = requests.get(basic_model_url)
|
33 |
with open(local_model_path, 'wb') as f:
|
34 |
f.write(response.content)
|
35 |
|
36 |
+
# Load the weights into the model
|
37 |
+
basic_model.load_weights(local_model_path)
|
38 |
|
39 |
# Load BERT Model and Tokenizer
|
40 |
bert_model = TFBertForSequenceClassification.from_pretrained(bert_model_name)
|
|
|
65 |
response = tf.argmax(outputs.logits, axis=-1).numpy()[0]
|
66 |
|
67 |
st.write(f"Bot: {response}")
|
68 |
+
|