Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add text-labelling function #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
7 changes: 4 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def webpage():
# redirect with url query param so that user can navigate back later
next_rec = service.get_next_unlabelled()
if next_rec:
return redirect("/?url=%s" % (urllib.quote(next_rec['url'])))
return redirect("/?url=%s" % (urllib.parse.quote(next_rec['url'])))
else:
featured_content = "No Unlabelled Record Found."
else:
Expand Down Expand Up @@ -84,7 +84,7 @@ def update():
next_rec = service.get_next_unlabelled()
target = "/"
if next_rec:
target += "?url=%s" % (urllib.quote(next_rec['url']))
target += "?url=%s" % (urllib.parse.quote(next_rec['url']))
return redirect(location=target)
else:
return abort(400, "Failed... No records updated")
Expand All @@ -104,7 +104,7 @@ def get_next(url=None):
next_rec = service.get_record(url)
url = next_rec['url']
template_name = '%s.html' % service.settings['type']
data_url = url if url.startswith('http') else "/proxy?url=%s" % urllib.quote(next_rec['url'])
data_url = url if url.startswith('http') else "/proxy?url=%s" % urllib.parse.quote(next_rec['url'])
data = {
'data_url' : data_url,
'url': url,
Expand Down Expand Up @@ -215,4 +215,5 @@ def __del__(self):
host = '0.0.0.0'
service = DbService(args['work_dir'], args['input'])
print("Starting on %s %s/" % (host, args['port']))
app.debug = True
app.run(host=host, port=args['port'])
1 change: 1 addition & 0 deletions rawdata/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test for labelling
45 changes: 45 additions & 0 deletions templates/text-labeling.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="featured-content">
<h2> Classify this image:</h2>
<div class="row-12">
<div class="col-md-6">
<form method="POST" action="/update" id="form">
<input type="hidden" name="url" value="{{ url }}">
{% for label in task.labels %}
<input type="checkbox" name="label" value="{{ label }}" id="checkbox_{{ label }}" style="width: 25px; height: 25px;">{{ loop.index }}) {{ label }}<br>
{% endfor %}
<br/>
<input type="submit" class="btn btn-primary" value="Submit">
<a class="btn btn-info" href="/"> Later </a>
</form>
</div>
<div class="col-md-6">
<p><iframe src="{{ data_url}}"frameborder="0" height="400"
width="95%"></iframe></p>
</div>
</div>
<hr/>
<div class="row">
<p> <i> <small>This text is from {{ url }}</small></i></p>
</div>


<script type="text/javascript">
document.onkeyup = function(e) {
e = e || window.event;

let key = String.fromCharCode(e.keyCode);

{% for label in task.labels %}
if (key == "{{ loop.index }}") {
let el = document.getElementById("checkbox_{{ label }}");
el.checked = !el.checked;
}
{% endfor %}

// submit on enter
if (e.keyCode == 13) {
document.getElementById("form").submit();
}
};
</script>
</div>
Binary file added workdir/.DS_Store
Binary file not shown.
Binary file added workdir/db.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions workdir/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/billyzhaoyh/Desktop/AIforGood/supervising-ui/rawdata/test.txt
6 changes: 2 additions & 4 deletions workdir/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"type": "image-labeling",
"type": "text-labeling",
"task": {
"labels":[
"class1",
"class2",
"class3",
"class4"
"class2"
]
}
}