deeksonparlma commited on
Commit ·
4ea55c2
1
Parent(s): 1a88edc
add tokenizer
Browse files- app.py +5 -2
- model.ipynb +18 -19
app.py
CHANGED
|
@@ -10,14 +10,17 @@
|
|
| 10 |
# write a gradio interface for tabibu-ai/mental-health-chatbot in huggingfacehub
|
| 11 |
|
| 12 |
# Path: app.py
|
|
|
|
| 13 |
import gradio as gr
|
| 14 |
|
| 15 |
# install transformers and torch in requirements.txt
|
| 16 |
|
| 17 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 18 |
|
| 19 |
-
tokenizer = AutoTokenizer.from_pretrained("tabibu-ai/mental-health-chatbot")
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def classify_text(inp):
|
| 23 |
input_ids = tokenizer.encode(inp, return_tensors='pt')
|
|
|
|
| 10 |
# write a gradio interface for tabibu-ai/mental-health-chatbot in huggingfacehub
|
| 11 |
|
| 12 |
# Path: app.py
|
| 13 |
+
import pickle
|
| 14 |
import gradio as gr
|
| 15 |
|
| 16 |
# install transformers and torch in requirements.txt
|
| 17 |
|
| 18 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 19 |
|
| 20 |
+
# tokenizer = AutoTokenizer.from_pretrained("tabibu-ai/mental-health-chatbot")
|
| 21 |
+
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained("rabiaqayyum/autotrain-mental-health-analysis-752423172")
|
| 23 |
+
model = pickle.load(open("model.pkl", "rb"))
|
| 24 |
|
| 25 |
def classify_text(inp):
|
| 26 |
input_ids = tokenizer.encode(inp, return_tensors='pt')
|
model.ipynb
CHANGED
|
@@ -2,19 +2,10 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"id": "ace57031",
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [
|
| 9 |
-
{
|
| 10 |
-
"name": "stderr",
|
| 11 |
-
"output_type": "stream",
|
| 12 |
-
"text": [
|
| 13 |
-
"2023-02-21 17:41:49.330107: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory\n",
|
| 14 |
-
"2023-02-21 17:41:49.330992: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory\n",
|
| 15 |
-
"2023-02-21 17:41:49.331010: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\n"
|
| 16 |
-
]
|
| 17 |
-
},
|
| 18 |
{
|
| 19 |
"data": {
|
| 20 |
"text/html": [
|
|
@@ -92,7 +83,7 @@
|
|
| 92 |
"4 When healing from mental illness, early identi... "
|
| 93 |
]
|
| 94 |
},
|
| 95 |
-
"execution_count":
|
| 96 |
"metadata": {},
|
| 97 |
"output_type": "execute_result"
|
| 98 |
}
|
|
@@ -141,7 +132,7 @@
|
|
| 141 |
},
|
| 142 |
{
|
| 143 |
"cell_type": "code",
|
| 144 |
-
"execution_count":
|
| 145 |
"id": "8f51e39d",
|
| 146 |
"metadata": {},
|
| 147 |
"outputs": [
|
|
@@ -162,7 +153,7 @@
|
|
| 162 |
},
|
| 163 |
{
|
| 164 |
"cell_type": "code",
|
| 165 |
-
"execution_count":
|
| 166 |
"id": "1d697a39",
|
| 167 |
"metadata": {},
|
| 168 |
"outputs": [
|
|
@@ -190,7 +181,7 @@
|
|
| 190 |
},
|
| 191 |
{
|
| 192 |
"cell_type": "code",
|
| 193 |
-
"execution_count":
|
| 194 |
"id": "c5dde0e4",
|
| 195 |
"metadata": {},
|
| 196 |
"outputs": [
|
|
@@ -198,7 +189,7 @@
|
|
| 198 |
"name": "stdout",
|
| 199 |
"output_type": "stream",
|
| 200 |
"text": [
|
| 201 |
-
"Accuracy: 0.
|
| 202 |
]
|
| 203 |
}
|
| 204 |
],
|
|
@@ -247,20 +238,28 @@
|
|
| 247 |
},
|
| 248 |
{
|
| 249 |
"cell_type": "code",
|
| 250 |
-
"execution_count":
|
| 251 |
"id": "14406312",
|
| 252 |
"metadata": {},
|
| 253 |
"outputs": [],
|
| 254 |
"source": [
|
| 255 |
-
"new_question =
|
| 256 |
]
|
| 257 |
},
|
| 258 |
{
|
| 259 |
"cell_type": "code",
|
| 260 |
-
"execution_count":
|
| 261 |
"id": "6b9198db",
|
| 262 |
"metadata": {},
|
| 263 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
"source": [
|
| 265 |
"new_question_vector = vectorizer.transform([new_question])\n",
|
| 266 |
"prediction = model.predict(new_question_vector)\n",
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
"id": "ace57031",
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
{
|
| 10 |
"data": {
|
| 11 |
"text/html": [
|
|
|
|
| 83 |
"4 When healing from mental illness, early identi... "
|
| 84 |
]
|
| 85 |
},
|
| 86 |
+
"execution_count": 2,
|
| 87 |
"metadata": {},
|
| 88 |
"output_type": "execute_result"
|
| 89 |
}
|
|
|
|
| 132 |
},
|
| 133 |
{
|
| 134 |
"cell_type": "code",
|
| 135 |
+
"execution_count": 3,
|
| 136 |
"id": "8f51e39d",
|
| 137 |
"metadata": {},
|
| 138 |
"outputs": [
|
|
|
|
| 153 |
},
|
| 154 |
{
|
| 155 |
"cell_type": "code",
|
| 156 |
+
"execution_count": 4,
|
| 157 |
"id": "1d697a39",
|
| 158 |
"metadata": {},
|
| 159 |
"outputs": [
|
|
|
|
| 181 |
},
|
| 182 |
{
|
| 183 |
"cell_type": "code",
|
| 184 |
+
"execution_count": 5,
|
| 185 |
"id": "c5dde0e4",
|
| 186 |
"metadata": {},
|
| 187 |
"outputs": [
|
|
|
|
| 189 |
"name": "stdout",
|
| 190 |
"output_type": "stream",
|
| 191 |
"text": [
|
| 192 |
+
"Accuracy: 0.06666666666666667\n"
|
| 193 |
]
|
| 194 |
}
|
| 195 |
],
|
|
|
|
| 238 |
},
|
| 239 |
{
|
| 240 |
"cell_type": "code",
|
| 241 |
+
"execution_count": 8,
|
| 242 |
"id": "14406312",
|
| 243 |
"metadata": {},
|
| 244 |
"outputs": [],
|
| 245 |
"source": [
|
| 246 |
+
"new_question = input(\"Ask me anything : \")\n"
|
| 247 |
]
|
| 248 |
},
|
| 249 |
{
|
| 250 |
"cell_type": "code",
|
| 251 |
+
"execution_count": 9,
|
| 252 |
"id": "6b9198db",
|
| 253 |
"metadata": {},
|
| 254 |
+
"outputs": [
|
| 255 |
+
{
|
| 256 |
+
"name": "stdout",
|
| 257 |
+
"output_type": "stream",
|
| 258 |
+
"text": [
|
| 259 |
+
"Prediction: ['\"Different kinds of therapy are more effective based on the nature of the mental health condition and/or symptoms and the person who has them (for example']\n"
|
| 260 |
+
]
|
| 261 |
+
}
|
| 262 |
+
],
|
| 263 |
"source": [
|
| 264 |
"new_question_vector = vectorizer.transform([new_question])\n",
|
| 265 |
"prediction = model.predict(new_question_vector)\n",
|