-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·146 lines (108 loc) · 4.97 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from flask import Flask, render_template, url_for, request, redirect
from ner import test_camel
from helpers import helper
from newNer import predict_sent
import os
import subprocess
import logging
import shutil
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/service', methods=['GET', 'POST'])
def test():
# if request.method == "POST":
# inp = request.form['input']
# sentence = helper.prepare_sentence(inp)
# task = test_camel(sentence)
# # task = helper.final_result(task)
# return render_template('service.html', task=task, inp=inp, res=res, size=size, links=links)
# else:
# return render_template('service.html', task='', inp='', res=[], size=0)
if request.method == "POST":
print('yes post')
inp = request.form['input']
print(inp)
options = request.form.get('options')
print(options)
if(options == "camel"):
sentence = helper.prepare_sentence(inp)
task, labels , tokens = test_camel(sentence)
res = helper.get_separate_entities(labels, tokens)
links = helper.get_wiki_urls(res)
size = len(res)
#task = helper.final_result(task)
print(task)
return render_template('service.html', task=task, inp=inp, res=res, size=size, links=links, model="Camel model")
else:
sentence = helper.prepare_sentence(inp)
#task = test_camel(sentence)
task, labels, tokens= predict_sent(sentence)
print('task')
print(type(task))
#!todo
#3- handling style
res = helper.get_separate_entities(labels, tokens)
links = helper.get_wiki_urls(res)
# task = helper.final_result(task)
size = len(res)
return render_template('service.html', task=task, inp=inp, res=res, size=size, links=links, model="Default model")
else:
return render_template('service.html', task='', inp='', res=[], size=0, links=[], model="Default model")
@app.route('/faq')
def faq():
return render_template('faq.html')
if __name__ == '__main__':
# model_path = os.path.dirname(os.path.abspath(__file__))+'/model/camel'
# model_path = os.path.dirname(os.path.abspath(__file__))+'/model/camel'
# # os.environ["CAMELTOOLS_DATA"] = model_path
# subprocess.call( 'mkdir /root/.camel_tools/', shell=True)
# subprocess.call( 'mkdir /root/.camel_tools/', shell=True)
# copy_path = model_path+'/data'
# copy_path = model_path+'/data'
# # subprocess.call( 'sudo cp -r '+ copy_path + '/ ' + '/root/.camel_tools/' , shell=True)
# subprocess.call( 'cp -r '+ copy_path + '/ ' + '/root/.camel_tools/' , shell=True)
# subprocess.call( 'cp -r '+ copy_path + '/ ' + '/root/.camel_tools/' , shell=True)
# shutil.copy(copy_path,'/root/.camel_tools/' )
# subprocess.call( 'sudo cp -r '+ model_path + ' ' + '/root/.camel_tools/' , shell=True)
# print(subprocess.call('echo $CAMELTOOLS_DATA' , shell=True))
# print(model_path)
# print(copy_path)
# print( os.listdir(model_path))
# print( os.listdir('/root/.camel_tools/'))
# print( os.listdir('/root/'))
# print(subprocess.call(['ls', '-l', '/root/'] , shell=True))
# print(subprocess.call(['ls', '-l', '/root/.camel_tools/'] , shell=True))
# try:
# base_path = os.path.expanduser('~')
# path = os.path.expanduser('~')+ '/ANER_DEV/model/camel/'
# os.environ["CAMELTOOLS_DATA"] = path
# if not os.path.exists(path + 'data'):
# # os.system('export CAMELTOOLS_DATA=$path')
# print(path)
# # subprocess.call([ 'export', 'CAMELTOOLS_DATA=', str(path)] , shell=True)
# print(subprocess.call('echo $CAMELTOOLS_DATA' , shell=True))
# os.system('camel_data full')
# else:
# print(path)
# print(base_path)
# if not os.path.exists(base_path+'/.camel_tools/'):
# subprocess.call( [ 'mkdir' , base_path+'/.camel_tools/'] , shell=True)
# dest = base_path+'/.camel_tools/'
# print(dest)
# subprocess.call( 'cp -r '+ path+'/data/' + ' ' + dest , shell=True)
# subprocess.call( 'sudo cp -r '+ path+'/data/' + ' ' + '/.camel_tools/' , shell=True)
# if not os.path.exists(base_path+'/root/.camel_tools/'):
# subprocess.call( [ 'mkdir' , '/root/.camel_tools/'] , shell=True)
# subprocess.call( 'sudo cp -r '+ path+'/data/' + ' ' + '/root/.camel_tools/' , shell=True)
# print('camel arelady downloaded')
# except:
# print('cant download camel')
app.run(debug=True)