Spaces:
Runtime error
Runtime error
David Kagramanyan
commited on
Commit
·
a1b76f2
1
Parent(s):
d5aeed8
initial
Browse files- app.py +30 -0
- ner_v0_model.ipynb +80 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
|
5 |
+
def compute_ner(input_text_message):
|
6 |
+
|
7 |
+
endpoint_url = 'https://on1m82uknekghqeh.us-east-1.aws.endpoints.huggingface.cloud'
|
8 |
+
|
9 |
+
headers = {
|
10 |
+
'Authorization': 'Bearer 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',
|
11 |
+
'Content-Type': 'application/json',
|
12 |
+
}
|
13 |
+
|
14 |
+
json_data = {
|
15 |
+
'inputs': input_text_message,
|
16 |
+
}
|
17 |
+
|
18 |
+
response = requests.post(endpoint_url, headers=headers, json=json_data)
|
19 |
+
|
20 |
+
result = response.json()
|
21 |
+
|
22 |
+
return {"text": input_text_message, "entities": result}
|
23 |
+
|
24 |
+
|
25 |
+
examples = ['You are dick', 'My dad is an asshole and took his anger out on my mom by verbally abusing her and when she left he eventually moved on to my brother']
|
26 |
+
iface = gr.Interface(fn=compute_ner,
|
27 |
+
inputs=gr.Textbox(placeholder="Enter sentence here"),
|
28 |
+
outputs=gr.HighlightedText(),
|
29 |
+
examples=examples)
|
30 |
+
iface.launch()
|
ner_v0_model.ipynb
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 requests"
|
16 |
+
]
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"cell_type": "code",
|
20 |
+
"execution_count": null,
|
21 |
+
"outputs": [],
|
22 |
+
"source": [
|
23 |
+
"\n",
|
24 |
+
"def compute_ner(input_text_message):\n",
|
25 |
+
"\n",
|
26 |
+
" endpoint_url = 'https://on1m82uknekghqeh.us-east-1.aws.endpoints.huggingface.cloud'\n",
|
27 |
+
"\n",
|
28 |
+
" headers = {\n",
|
29 |
+
" 'Authorization': 'Bearer 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',\n",
|
30 |
+
" 'Content-Type': 'application/json',\n",
|
31 |
+
" }\n",
|
32 |
+
"\n",
|
33 |
+
" json_data = {\n",
|
34 |
+
" 'inputs': input_text_message,\n",
|
35 |
+
" }\n",
|
36 |
+
"\n",
|
37 |
+
" response = requests.post(endpoint_url, headers=headers, json=json_data)\n",
|
38 |
+
"\n",
|
39 |
+
" result = response.json()\n",
|
40 |
+
"\n",
|
41 |
+
" return {\"text\": input_text_message, \"entities\": result}\n",
|
42 |
+
"\n",
|
43 |
+
"\n",
|
44 |
+
"examples = ['You are dick', 'My dad is an asshole and took his anger out on my mom by verbally abusing her and when she left he eventually moved on to my brother']\n",
|
45 |
+
"iface = gr.Interface(fn=compute_ner,\n",
|
46 |
+
" inputs=gr.Textbox(placeholder=\"Enter sentence here\"),\n",
|
47 |
+
" outputs=gr.HighlightedText(),\n",
|
48 |
+
" examples=examples)\n",
|
49 |
+
"iface.launch()"
|
50 |
+
],
|
51 |
+
"metadata": {
|
52 |
+
"collapsed": false,
|
53 |
+
"pycharm": {
|
54 |
+
"name": "#%%\n"
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
],
|
59 |
+
"metadata": {
|
60 |
+
"kernelspec": {
|
61 |
+
"name": "torch",
|
62 |
+
"language": "python",
|
63 |
+
"display_name": "torch"
|
64 |
+
},
|
65 |
+
"language_info": {
|
66 |
+
"codemirror_mode": {
|
67 |
+
"name": "ipython",
|
68 |
+
"version": 2
|
69 |
+
},
|
70 |
+
"file_extension": ".py",
|
71 |
+
"mimetype": "text/x-python",
|
72 |
+
"name": "python",
|
73 |
+
"nbconvert_exporter": "python",
|
74 |
+
"pygments_lexer": "ipython2",
|
75 |
+
"version": "2.7.6"
|
76 |
+
}
|
77 |
+
},
|
78 |
+
"nbformat": 4,
|
79 |
+
"nbformat_minor": 0
|
80 |
+
}
|