Skip to content

Commit c4ccb34

Browse files
authored
Merge pull request #1 from viole4244/main
LOML
2 parents 6616865 + 439e2b9 commit c4ccb34

File tree

9 files changed

+8195
-0
lines changed

9 files changed

+8195
-0
lines changed

__pycache__/streamlit.cpython-310.pyc

469 Bytes
Binary file not shown.

app.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
import streamlit as st
3+
import numpy as np
4+
import tensorflow as tf
5+
from tensorflow.keras.models import load_model
6+
from tensorflow.keras.preprocessing.sequence import pad_sequences
7+
import pickle
8+
9+
# Load the model, tokenizer, and label encoder
10+
model = load_model('chatbot_model.h5')
11+
12+
with open('tokenizer.pickle', 'rb') as handle:
13+
tokenizer = pickle.load(handle)
14+
15+
with open('label_encoder.pickle', 'rb') as handle:
16+
label_encoder = pickle.load(handle)
17+
18+
# Function to predict intents based on user input
19+
def predict_intent(user_input):
20+
user_input_seq = tokenizer.texts_to_sequences([user_input])
21+
user_input_pad = pad_sequences(user_input_seq, maxlen=model.input_shape[1], padding='post')
22+
prediction = model.predict(user_input_pad)
23+
intent = label_encoder.inverse_transform([np.argmax(prediction)])
24+
return intent[0]
25+
26+
# Function to generate responses based on predicted intents
27+
def generate_response(intent):
28+
with open('therapy_data.json', 'r') as f:
29+
data = json.load(f)
30+
responses = [i['responses'] for i in data['intents'] if i['tag'] == intent]
31+
response = np.random.choice(responses[0])
32+
return response
33+
34+
# Streamlit UI
35+
st.title("AI Therapy Chatbot")
36+
37+
user_input = st.text_input("You:", "")
38+
39+
if user_input:
40+
intent = predict_intent(user_input)
41+
response = generate_response(intent)
42+
st.write(f"Chatbot: {response}")

chat.ipynb

Lines changed: 1522 additions & 0 deletions
Large diffs are not rendered by default.

chatbot_model.h5

17.1 MB
Binary file not shown.

label_encoder.pickle

1.06 KB
Binary file not shown.

req.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flask
2+
google-cloud-vertex-ai
3+
pandas
4+
transformers

therapy_data.csv

Lines changed: 6303 additions & 0 deletions
Large diffs are not rendered by default.

therapy_data.json

Lines changed: 324 additions & 0 deletions
Large diffs are not rendered by default.

tokenizer.pickle

8.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)