Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 58
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 58
22_23-J 58
Commits
8af5b7d4
Commit
8af5b7d4
authored
Apr 24, 2023
by
IT19974156_Nawagamuwa.N.G.K
🥇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
main.py
parent
f94e16b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
main.py
main.py
+57
-0
No files found.
main.py
0 → 100644
View file @
8af5b7d4
from
fastapi
import
FastAPI
,
Request
,
Form
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
HTMLResponse
from
fastapi.staticfiles
import
StaticFiles
from
fastapi.templating
import
Jinja2Templates
from
uvicorn
import
run
import
numpy
as
np
import
os
import
joblib
import
json
app
=
FastAPI
()
origins
=
[
"*"
]
methods
=
[
"*"
]
headers
=
[
"*"
]
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
allow_credentials
=
True
,
allow_methods
=
methods
,
allow_headers
=
headers
)
app
.
mount
(
"/static"
,
StaticFiles
(
directory
=
"static"
),
name
=
"static"
)
templates
=
Jinja2Templates
(
directory
=
"templates"
)
def
getPredict
(
topredict
):
kn_classifier2
=
joblib
.
load
(
'fishRecModel.pkl'
,
mmap_mode
=
'r'
)
prediction
=
kn_classifier2
.
predict
((
topredict
))
return
prediction
@
app
.
get
(
"/home"
,
response_class
=
HTMLResponse
)
async
def
homePage
(
request
:
Request
):
return
templates
.
TemplateResponse
(
"index.html"
,
{
"request"
:
request
})
@
app
.
post
(
"/result"
,
response_class
=
HTMLResponse
)
async
def
resultPage
(
request
:
Request
,
NH3
:
str
=
Form
(
...
),
NO2
:
str
=
Form
(
...
),
NO3
:
str
=
Form
(
...
),
Temprature
:
str
=
Form
(
...
),
Oxygen
:
str
=
Form
(
...
),
PH
:
str
=
Form
(
...
)):
to_predict_list
=
np
.
array
([[
NH3
,
NO2
,
NO3
,
Temprature
,
Oxygen
,
PH
]])
prediction_r
=
getPredict
(
to_predict_list
)
resultlist
=
prediction_r
.
tolist
()
json_str
=
json
.
dumps
(
resultlist
)
outcome
=
json_str
.
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
)
return
templates
.
TemplateResponse
(
"result.html"
,
{
"request"
:
request
,
"prediction"
:
outcome
})
if
__name__
==
"__main__"
:
port
=
int
(
os
.
environ
.
get
(
'PORT'
,
5000
))
run
(
app
,
host
=
"0.0.0.0"
,
port
=
port
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment