-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
82 lines (69 loc) · 1.85 KB
/
code.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
import web
import json
import text_analysis_gui as tag
from predict_ml import predict_CPN
import mapping as mp
import database
urls = (
'/index','index',
'/test', 'test',
'/prediction','prediction',
'/prediction2','prediction2',
'/classify','classify',
'/static/(.*)','static',
'/demo','demo',
'/search','search',
'/request','request'
)
name="Qing"
dic=mp.demo_dict
dic_keys=dic.keys()
render = web.template.render('templates/')
class index:
def GET(self):
return render.index(name,dic,dic_keys)
class test:
def GET(self):
user_data=web.input()
text=' '.join(user_data.values())
text=tag.remove_address_info(text)
word_freq=tag.calculate_all_text_freq(text)
category=predict_CPN(word_freq)
return category
class prediction:
def GET(self):
return render.prediction()
class prediction2:
def GET(self):
return render.prediction2(dic_keys,dic)
class classify:
def GET(self):
user_data=web.input()
text=' '.join(user_data.values())
text=tag.remove_address_info(text)
word_freq=tag.calculate_all_text_freq(text)
category,desc=predict_CPN(word_freq)
img_file='static/img/'+category+'.jpg'
cpn='Component Number: '+category
pyDict={"CPN":cpn,"img_file":img_file,"DESC":desc}
web.header('Content-Type','application/json')
return json.dumps(pyDict)
class search:
def GET(self):
# usr_data=web.input()
return render.search_index()
# return json.dumps(usr_data)
class request:
def GET(self):
usr_data=web.input()
return database.get_entry_by_category(usr_data.values()[0])
class static:
def GET(self,filename):
f=open('static'+filename)
print f.read()
class demo:
def GET(self):
return 'this is demo page'
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()