forked from russellromney/fetchilarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.py
110 lines (90 loc) · 2.51 KB
/
webapp.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
import dash
from dash import no_update
from dash.dependencies import Input,Output,State
import dash_bootstrap_components as dbc
import dash_html_components as html
import dash_core_components as dcc
from utilities import fetchilarity_score
app = dash.Dash(__name__,external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
app.layout = html.Div([
dbc.Container(
[
dbc.Row(
dbc.Col(
dcc.Markdown(
'''
# Fetchilarity
### Enter two bits of text to determine how similar they are!
Made with love by Russell.
'''
),
),
style=dict(textAlign='center')
),
dbc.Row(
[
# enter text1
dbc.Col(
[
dbc.Textarea(placeholder='Enter the first bit of text',id='text1'),
],
width=6
),
# enter text2
dbc.Col(
[
dbc.Textarea(placeholder='Enter the second bit of text',id='text2'),
],
width=6
)
]
),
html.Br(),
dbc.Row(
[
dbc.Col(
dbc.Button('SUBMIT',id='submit',color='primary',size='lg',block=True,n_clicks=0)
),
],
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
html.Div(id='output',style=dict(textAlign='center'))
]
)
]
)
]
)
])
@app.callback(
Output('output','children'),
[Input('submit','n_clicks')],
[State('text1','value'),
State('text2','value')]
)
def get_score(n_clicks,text1,text2):
if n_clicks==0:
return no_update
try:
score = fetchilarity_score(text1,text2,mode='api')
except BaseException as e:
print(text1,text2)
print(e)
return 'something went terribly wrong with that input. Please try again.'
return dbc.Card(
[
html.H3('Fetchilarity Score',className='card-title'),
html.H1(str(round(score,4)))
],
body=True
)
if __name__ == "__main__":
app.run_server(
port=8050,
debug=True
)