Spaces:
Runtime error
Runtime error
David commited on
Commit ·
e1b9a32
1
Parent(s): 06881e2
added secrets lib
Browse files- ner_v0_model.ipynb +0 -197
ner_v0_model.ipynb
DELETED
|
@@ -1,197 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": null,
|
| 6 |
-
"metadata": {
|
| 7 |
-
"collapsed": true,
|
| 8 |
-
"pycharm": {
|
| 9 |
-
"name": "#%%\n"
|
| 10 |
-
}
|
| 11 |
-
},
|
| 12 |
-
"outputs": [],
|
| 13 |
-
"source": [
|
| 14 |
-
"import gradio as gr\n",
|
| 15 |
-
"import os\n",
|
| 16 |
-
"\n",
|
| 17 |
-
"os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'\n",
|
| 18 |
-
"import requests\n",
|
| 19 |
-
"\n",
|
| 20 |
-
"from spacy import displacy"
|
| 21 |
-
]
|
| 22 |
-
},
|
| 23 |
-
{
|
| 24 |
-
"cell_type": "code",
|
| 25 |
-
"execution_count": null,
|
| 26 |
-
"outputs": [],
|
| 27 |
-
"source": [
|
| 28 |
-
"\n",
|
| 29 |
-
"def compute_ner(input_text_message):\n",
|
| 30 |
-
" endpoint_url = 'https://on1m82uknekghqeh.us-east-1.aws.endpoints.huggingface.cloud'\n",
|
| 31 |
-
"\n",
|
| 32 |
-
" headers = {\n",
|
| 33 |
-
" 'Authorization': 'Bearer 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',\n",
|
| 34 |
-
" 'Content-Type': 'application/json',\n",
|
| 35 |
-
" }\n",
|
| 36 |
-
"\n",
|
| 37 |
-
" json_data = {\n",
|
| 38 |
-
" 'inputs': input_text_message,\n",
|
| 39 |
-
" }\n",
|
| 40 |
-
"\n",
|
| 41 |
-
" response = requests.post(endpoint_url, headers=headers, json=json_data)\n",
|
| 42 |
-
"\n",
|
| 43 |
-
" tokens = response.json()\n",
|
| 44 |
-
"\n",
|
| 45 |
-
" entities = []\n",
|
| 46 |
-
"\n",
|
| 47 |
-
" for token in tokens:\n",
|
| 48 |
-
" label = token[\"entity\"]\n",
|
| 49 |
-
"\n",
|
| 50 |
-
" if label == \"I-Observation\" or label == \"B-Observation\":\n",
|
| 51 |
-
" label = \"Observation\"\n",
|
| 52 |
-
" token[\"label\"] = label\n",
|
| 53 |
-
" entities.append(token)\n",
|
| 54 |
-
"\n",
|
| 55 |
-
" if label == \"I-Evaluation\" or label == \"B-Evaluation\":\n",
|
| 56 |
-
" label = \"Evaluation\"\n",
|
| 57 |
-
" token[\"label\"] = label\n",
|
| 58 |
-
" entities.append(token)\n",
|
| 59 |
-
"\n",
|
| 60 |
-
" params = [{\"text\": input_text_message,\n",
|
| 61 |
-
" \"ents\": entities,\n",
|
| 62 |
-
" \"title\": None}]\n",
|
| 63 |
-
"\n",
|
| 64 |
-
" return displacy.render(params, style=\"ent\", manual=True, options={\n",
|
| 65 |
-
" \"colors\": {\n",
|
| 66 |
-
" \"Observation\": \"#9bddff\",\n",
|
| 67 |
-
" \"Evaluation\": \"#f08080\",\n",
|
| 68 |
-
" },\n",
|
| 69 |
-
" })\n",
|
| 70 |
-
"\n",
|
| 71 |
-
"\n",
|
| 72 |
-
"examples = ['You are dick',\n",
|
| 73 |
-
" 'My dad is an asshole and took his anger out on my mom by verbally abusing her','He eventually moved on to my brother']\n",
|
| 74 |
-
"\n",
|
| 75 |
-
"iface = gr.Interface(fn=compute_ner, inputs=gr.inputs.Textbox(lines=5, placeholder=\"Enter your text here\",label='Check your text on NVC rules'),\n",
|
| 76 |
-
" outputs=\"html\", examples=examples,)\n",
|
| 77 |
-
"iface.launch(debug=True)"
|
| 78 |
-
],
|
| 79 |
-
"metadata": {
|
| 80 |
-
"collapsed": false,
|
| 81 |
-
"pycharm": {
|
| 82 |
-
"name": "#%%\n"
|
| 83 |
-
}
|
| 84 |
-
}
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"cell_type": "code",
|
| 88 |
-
"execution_count": null,
|
| 89 |
-
"outputs": [],
|
| 90 |
-
"source": [
|
| 91 |
-
"endpoint_url = 'https://on1m82uknekghqeh.us-east-1.aws.endpoints.huggingface.cloud'\n",
|
| 92 |
-
"\n",
|
| 93 |
-
"headers = {\n",
|
| 94 |
-
" 'Authorization': 'Bearer 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',\n",
|
| 95 |
-
" 'Content-Type': 'application/json',\n",
|
| 96 |
-
"}\n",
|
| 97 |
-
"\n",
|
| 98 |
-
"json_data = {\n",
|
| 99 |
-
" 'inputs': 'you are dick',\n",
|
| 100 |
-
"}\n",
|
| 101 |
-
"\n",
|
| 102 |
-
"response = requests.post(endpoint_url, headers=headers, json=json_data)\n",
|
| 103 |
-
"\n",
|
| 104 |
-
"tokens = response.json()"
|
| 105 |
-
],
|
| 106 |
-
"metadata": {
|
| 107 |
-
"collapsed": false,
|
| 108 |
-
"pycharm": {
|
| 109 |
-
"name": "#%%\n"
|
| 110 |
-
}
|
| 111 |
-
}
|
| 112 |
-
},
|
| 113 |
-
{
|
| 114 |
-
"cell_type": "code",
|
| 115 |
-
"execution_count": null,
|
| 116 |
-
"outputs": [],
|
| 117 |
-
"source": [
|
| 118 |
-
"tokens"
|
| 119 |
-
],
|
| 120 |
-
"metadata": {
|
| 121 |
-
"collapsed": false,
|
| 122 |
-
"pycharm": {
|
| 123 |
-
"name": "#%%\n"
|
| 124 |
-
}
|
| 125 |
-
}
|
| 126 |
-
},
|
| 127 |
-
{
|
| 128 |
-
"cell_type": "code",
|
| 129 |
-
"execution_count": null,
|
| 130 |
-
"outputs": [],
|
| 131 |
-
"source": [
|
| 132 |
-
"import spacy\n",
|
| 133 |
-
"from spacy import displacy"
|
| 134 |
-
],
|
| 135 |
-
"metadata": {
|
| 136 |
-
"collapsed": false,
|
| 137 |
-
"pycharm": {
|
| 138 |
-
"name": "#%%\n"
|
| 139 |
-
}
|
| 140 |
-
}
|
| 141 |
-
},
|
| 142 |
-
{
|
| 143 |
-
"cell_type": "code",
|
| 144 |
-
"execution_count": null,
|
| 145 |
-
"outputs": [],
|
| 146 |
-
"source": [
|
| 147 |
-
"!python -m spacy download en_core_web_sm"
|
| 148 |
-
],
|
| 149 |
-
"metadata": {
|
| 150 |
-
"collapsed": false,
|
| 151 |
-
"pycharm": {
|
| 152 |
-
"name": "#%%\n"
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
},
|
| 156 |
-
{
|
| 157 |
-
"cell_type": "code",
|
| 158 |
-
"execution_count": null,
|
| 159 |
-
"outputs": [],
|
| 160 |
-
"source": [
|
| 161 |
-
"\n",
|
| 162 |
-
"text = \"When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously.\"\n",
|
| 163 |
-
"\n",
|
| 164 |
-
"nlp = spacy.load(\"en_core_web_sm\")\n",
|
| 165 |
-
"doc = nlp(text)\n",
|
| 166 |
-
"displacy.serve(doc, style=\"ent\")"
|
| 167 |
-
],
|
| 168 |
-
"metadata": {
|
| 169 |
-
"collapsed": false,
|
| 170 |
-
"pycharm": {
|
| 171 |
-
"name": "#%%\n"
|
| 172 |
-
}
|
| 173 |
-
}
|
| 174 |
-
}
|
| 175 |
-
],
|
| 176 |
-
"metadata": {
|
| 177 |
-
"kernelspec": {
|
| 178 |
-
"name": "torch",
|
| 179 |
-
"language": "python",
|
| 180 |
-
"display_name": "torch"
|
| 181 |
-
},
|
| 182 |
-
"language_info": {
|
| 183 |
-
"codemirror_mode": {
|
| 184 |
-
"name": "ipython",
|
| 185 |
-
"version": 2
|
| 186 |
-
},
|
| 187 |
-
"file_extension": ".py",
|
| 188 |
-
"mimetype": "text/x-python",
|
| 189 |
-
"name": "python",
|
| 190 |
-
"nbconvert_exporter": "python",
|
| 191 |
-
"pygments_lexer": "ipython2",
|
| 192 |
-
"version": "2.7.6"
|
| 193 |
-
}
|
| 194 |
-
},
|
| 195 |
-
"nbformat": 4,
|
| 196 |
-
"nbformat_minor": 0
|
| 197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