-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.py
237 lines (154 loc) · 6.07 KB
/
index.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from flask import Flask
from flask_restful import Resource, Api
from flask import request
import time
import dash_bootstrap_components as dbc
import dash_daq as daq
from dash.dependencies import Input, Output,State
import mod
import time
# external JS
external_scripts = [
'https://www.google-analytics.com/analytics.js',
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js",
{'src': 'https://cdn.polyfill.io/v2/polyfill.min.js'},
{
'src': 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.core.js',
'integrity': 'sha256-Qqd/EfdABZUcAxjOkMi8eGEivtdTkh3b65xCZL4qAQA=',
'crossorigin': 'anonymous'
}
]
# external CSS stylesheets
external_stylesheets = [
'https://codepen.io/chriddyp/pen/bWLwgP.css',
{
'href': 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css',
'rel': 'stylesheet',
'integrity': 'sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO',
'crossorigin': 'anonymous'
},
{
'href': 'https://fonts.googleapis.com/css?family=Varela',
'rel': 'stylesheet',
'integrity': 'sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO',
'crossorigin': 'anonymous'
}
]
app = dash.Dash(__name__, meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"}
],
external_scripts=external_scripts,
external_stylesheets=external_stylesheets)
app.title = 'Fake News Predictor | An open source tool to predict fake news using machine learning.'
app.config['suppress_callback_exceptions']=True
server = app.server
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
PLOTLY_LOGO = "/"
#server = Flask('my_app')
#app = dash.Dash(server=server)
api = Api(server)
todos = {}
class HelloWorld(Resource):
def get(self):
return " "
def put(self):
sT=str(request.form['data'])
numericValue=mod.runs(str(sT))*10
return str(numericValue)
api.add_resource(HelloWorld, '/hello')
# Update the index
@app.callback(dash.dependencies.Output('page-content', 'children'),
[dash.dependencies.Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/':
# Default path is / . It will render Page_1_layout
return page_1_layout
elif pathname=='/validate':
return page_2_layout
else:
return []
# You could also return a 404 "URL not found" page here
page_1_layout = html.Div([
# Creating a Navbar
dbc.Navbar(
[
html.A(
# Use row and col to control vertical alignment of logo / brand
dbc.Row(
[
dbc.Col(html.Img(src="assets/keras-logo-small-wb-1.png", height="30px")),
dbc.Col(dbc.NavbarBrand("FakeNews Detection", className="ml-4")),
],
align="center",
no_gutters=True,
),
href="/",
),
dbc.NavbarToggler(id="navbar-toggler"),
],
color="dark",
dark=True,
sticky="top",
),
html.Div([
html.Div([
dcc.Interval(id="interval", interval=250, n_intervals=0),
html.Div([
html.Div(id='variables',children=[],style={"display":"None"}),
# Inside this class we are making dcc.Upload which will upload our image.
dbc.Card(
[
dbc.CardHeader("FakeNews Detection \u2b50"),
dbc.CardBody(
[html.Div([
html.Div([
html.Div([
html.H5('Enter Your News \ud83d\udcbb'),
html.Div([
dcc.Input(
id="fake-news-text",
placeholder='Enter Your News',
type='text',
value='',
style={"width":"50%"}
),
html.Div([
dbc.Button("Submit \ud83d\udc4b", id="fake-news-button", className="mr-1",color="warning",outline=True,style={"margin-top":"3%","margin-top":"5px",'border':"#FFC107 2px solid "})
],className="twelve columns"),
],className="twelve columns",style={'margin-bottom':'10px'}),
],className='twelve columns'),
],className='twelve columns'),
],className="ten columns offset-by-one") ]), ]
),],style={ 'margin-top':'3%'}),
html.Div(id='output-image',style={"margin-top":"10px","margin-bottom":"10px"}),
html.Div(id='output-image-1',style={"margin-top":"10px","margin-":"10px"}),
],className='ten columns offset-by-one'),
]),
])
@app.callback(Output('output-image', 'children'),
[Input('fake-news-button','n_clicks')],
[State('fake-news-text', 'value')])
def update_graph_interactive_images(buttons,text):
if text=="":
return ''
numericValue=mod.runs(str(text))*10
print(numericValue)
gauge=daq.Gauge(
showCurrentValue=True,
color='#FFC107',
value=numericValue,
label='True-Meter',
max=10,
min=0,
)
return gauge
page_2_layout = html.Div([])
if __name__ == '__main__':
app.run_server(debug=True)