Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
e2e-coref
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guanxing
e2e-coref
Commits
1f37582e
Commit
1f37582e
authored
Nov 01, 2017
by
Kenton Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made visualization for long documents more readable.
parent
25dff938
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
37 deletions
+48
-37
demo.py
demo.py
+27
-25
deploy.sh
html/deploy.sh
+1
-1
index.html
html/index.html
+4
-3
main.css
html/main.css
+4
-0
query.cgi
html/query.cgi
+12
-8
No files found.
demo.py
View file @
1f37582e
...
@@ -7,7 +7,7 @@ import json
...
@@ -7,7 +7,7 @@ import json
import
numpy
as
np
import
numpy
as
np
import
cgi
import
cgi
import
BaseHTTPServ
er
from
BaseHTTPServer
import
HTTPServer
,
BaseHTTPRequestHandl
er
import
ssl
import
ssl
import
tensorflow
as
tf
import
tensorflow
as
tf
...
@@ -18,6 +18,30 @@ import nltk
...
@@ -18,6 +18,30 @@ import nltk
nltk
.
download
(
"punkt"
)
nltk
.
download
(
"punkt"
)
from
nltk.tokenize
import
sent_tokenize
,
word_tokenize
from
nltk.tokenize
import
sent_tokenize
,
word_tokenize
class
CorefRequestHandler
(
BaseHTTPRequestHandler
):
model
=
None
def
do_POST
(
self
):
form
=
cgi
.
FieldStorage
(
fp
=
self
.
rfile
,
headers
=
self
.
headers
,
environ
=
{
"REQUEST_METHOD"
:
"POST"
,
"CONTENT_TYPE"
:
self
.
headers
[
"Content-Type"
]
})
if
"text"
in
form
:
text
=
form
[
"text"
]
.
value
.
decode
(
"utf-8"
)
if
len
(
text
)
<=
10000
:
print
(
u"Document text: {}"
.
format
(
text
))
example
=
make_predictions
(
text
,
self
.
model
)
print_predictions
(
example
)
self
.
send_response
(
200
)
self
.
send_header
(
"Content-Type"
,
"application/json"
)
self
.
end_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
example
))
return
self
.
send_response
(
400
)
self
.
send_header
(
"Content-Type"
,
"application/json"
)
self
.
end_headers
()
def
create_example
(
text
):
def
create_example
(
text
):
raw_sentences
=
sent_tokenize
(
text
)
raw_sentences
=
sent_tokenize
(
text
)
sentences
=
[
word_tokenize
(
s
)
for
s
in
raw_sentences
]
sentences
=
[
word_tokenize
(
s
)
for
s
in
raw_sentences
]
...
@@ -71,30 +95,8 @@ if __name__ == "__main__":
...
@@ -71,30 +95,8 @@ if __name__ == "__main__":
saver
.
restore
(
session
,
checkpoint_path
)
saver
.
restore
(
session
,
checkpoint_path
)
if
port
is
not
None
:
if
port
is
not
None
:
class
CorefRequestHandler
(
BaseHTTPServer
.
BaseHTTPRequestHandler
):
CorefRequestHandler
.
model
=
model
def
do_POST
(
self
):
server
=
HTTPServer
((
""
,
port
),
CorefRequestHandler
)
form
=
cgi
.
FieldStorage
(
fp
=
self
.
rfile
,
headers
=
self
.
headers
,
environ
=
{
"REQUEST_METHOD"
:
"POST"
,
"CONTENT_TYPE"
:
self
.
headers
[
"Content-Type"
]
})
if
"text"
in
form
:
text
=
form
[
"text"
]
.
value
.
decode
(
"utf-8"
)
if
len
(
text
)
<=
10000
:
print
(
u"Document text: {}"
.
format
(
text
))
example
=
make_predictions
(
text
,
model
)
print_predictions
(
example
)
self
.
send_response
(
200
)
self
.
send_header
(
"Content-Type"
,
"application/json"
)
self
.
end_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
example
))
return
self
.
send_response
(
400
)
self
.
send_header
(
"Content-Type"
,
"application/json"
)
self
.
end_headers
()
server
=
BaseHTTPServer
.
HTTPServer
((
""
,
port
),
CorefRequestHandler
)
print
(
"Running server at port {}"
.
format
(
port
))
print
(
"Running server at port {}"
.
format
(
port
))
server
.
serve_forever
()
server
.
serve_forever
()
else
:
else
:
...
...
html/deploy.sh
View file @
1f37582e
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,4 @@
html_root
=
~/public_html
html_root
=
~/public_html
name
=
e2e-coref
name
=
e2e-coref
mkdir
-p
$html_root
/
$name
mkdir
-p
$html_root
/
$name
cp
index.html main.js query.cgi
$html_root
/
$name
cp
index.html main.js
main.css
query.cgi
$html_root
/
$name
html/index.html
View file @
1f37582e
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
<script
src=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
></script>
<script
src=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
></script>
<script
src=
"main.js"
></script>
<script
src=
"main.js"
></script>
<link
rel=
"stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
href=
"main.css"
>
</head>
</head>
<body>
<body>
<div
class=
"container"
>
<div
class=
"container"
>
...
@@ -53,15 +54,15 @@
...
@@ -53,15 +54,15 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-3"
>
<div
class=
"col-md-3"
>
<h4
id=
"predicted-clusters-title"
></h4>
<h4
id=
"predicted-clusters-title"
></h4>
<ul
id=
"predicted-clusters"
class=
"list-group"
></ul>
<ul
id=
"predicted-clusters"
class=
"list-group
scrollable
"
></ul>
</div>
</div>
<div
class=
"col-md-6"
>
<div
class=
"col-md-6"
>
<h4
id=
"text-title"
></h4>
<h4
id=
"text-title"
></h4>
<p
id=
"text"
class=
"lead"
></p>
<p
id=
"text"
class=
"lead
scrollable
"
></p>
</div>
</div>
<div
class=
"col-md-3"
>
<div
class=
"col-md-3"
>
<h4
id=
"top-spans-title"
></h4>
<h4
id=
"top-spans-title"
></h4>
<ul
id=
"top-spans"
class=
"list-group"
></ul>
<ul
id=
"top-spans"
class=
"list-group
scrollable
"
></ul>
</div>
</div>
</div>
</div>
</body>
</body>
...
...
html/main.css
0 → 100644
View file @
1f37582e
.scrollable
{
max-height
:
800px
;
overflow-y
:
auto
;
}
html/query.cgi
View file @
1f37582e
...
@@ -9,18 +9,22 @@ cgitb.enable()
...
@@ -9,18 +9,22 @@ cgitb.enable()
SERVER
=
"http://localhost"
SERVER
=
"http://localhost"
PORT
=
10001
PORT
=
10001
def
print_header
():
print
"Content-Type: text/html"
print
def
print_error
(
errno
,
message
):
print
"Status: {} {}"
.
format
(
errno
,
message
)
print_header
()
sys
.
exit
()
form
=
cgi
.
FieldStorage
()
form
=
cgi
.
FieldStorage
()
if
"text"
not
in
form
:
if
"text"
not
in
form
:
print
"Status:
%
d
%
s
\n\n
"
%
(
400
,
"Bad Request"
)
print_error
(
400
,
"Bad Request"
)
sys
.
exit
(
0
)
text
=
form
.
getvalue
(
"text"
)
text
=
form
.
getvalue
(
"text"
)
try
:
try
:
post_response
=
requests
.
post
(
url
=
"{}:{}"
.
format
(
SERVER
,
PORT
),
data
=
{
"text"
:
text
},
timeout
=
180
)
post_response
=
requests
.
post
(
url
=
"{}:{}"
.
format
(
SERVER
,
PORT
),
data
=
{
"text"
:
text
},
timeout
=
180
)
except
requests
.
exceptions
.
ConnectionError
as
e
:
except
requests
.
exceptions
.
ConnectionError
as
e
:
print
e
print_error
(
503
,
"Service Unavailable"
)
sys
.
exit
(
0
)
print_header
()
print
"Content-Type: text/html"
print
print
post_response
.
text
.
encode
(
"utf-8"
)
print
post_response
.
text
.
encode
(
"utf-8"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment