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
7ad8c2ff
Commit
7ad8c2ff
authored
May 05, 2023
by
IT19955728_JathunarachchiRT
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python Source code
parent
bf1514cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
main.py
main.py
+124
-0
No files found.
main.py
0 → 100644
View file @
7ad8c2ff
from
fastapi
import
FastAPI
,
Request
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
HTMLResponse
from
fastapi.staticfiles
import
StaticFiles
from
fastapi.templating
import
Jinja2Templates
from
tensorflow.keras.models
import
load_model
from
tensorflow.keras.utils
import
get_file
from
tensorflow.keras.utils
import
load_img
from
tensorflow.keras.utils
import
img_to_array
from
tensorflow
import
expand_dims
from
tensorflow.nn
import
softmax
from
numpy
import
argmax
from
numpy
import
max
from
numpy
import
array
from
json
import
dumps
from
uvicorn
import
run
import
os
import
requests
import
shutil
app
=
FastAPI
()
origins
=
[
"*"
]
methods
=
[
"*"
]
headers
=
[
"*"
]
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
allow_credentials
=
True
,
allow_methods
=
methods
,
allow_headers
=
headers
)
model_dir
=
"Fish_identificaton.h5"
model
=
load_model
(
model_dir
)
# Providing the folder path
origin
=
r"C:\xampp\htdocs\templates\php\files\fishimage.jpg"
target
=
r"E:\4th Year\1st Sem\Research\Docker\Backend\fishimage.jpg"
target2
=
r"E:\4th Year\1st Sem\Research\Docker\Backend\templates\fishimage.jpg"
# Function to get result
# async def get_net_image_prediction(image_link: str = ""):
# if image_link == "":
# print(image_link)
# return {"message": "No image link provided"}
# response = requests.get(image_link)
# filename = "fishimage.jpg"
# with open(filename, "wb") as f:
# f.write(response.content)
# # img_path = get_file(
# # origin = image_link
# # )
def
get_net_image_prediction
():
# myfile = open('C:/xampp/htdocs/templates/php/files/fishimage.jpg')
# myfile = open('C:\\xampp\\htdocs\\templates\\php\\files\\fishimage.jpg','r')
shutil
.
copy
(
origin
,
target
)
shutil
.
copy
(
origin
,
target2
)
img_path
=
"fishimage.jpg"
img
=
load_img
(
img_path
,
target_size
=
(
331
,
331
)
)
img_array
=
img_to_array
(
img
)
img_array
=
expand_dims
(
img_array
,
0
)
pred
=
model
.
predict
(
img_array
)
max_value
=
max
(
pred
[
0
])
duplicate_list
=
list
(
pred
[
0
])
index
=
duplicate_list
.
index
(
max_value
)
lables
=
[
'feed'
,
'group'
,
'individual'
,
'aggresive'
,
'nervous'
]
rt
=
lables
[
index
]
return
{
rt
}
app
.
mount
(
"/static"
,
StaticFiles
(
directory
=
"static"
),
name
=
"static"
)
templates
=
Jinja2Templates
(
directory
=
"templates"
)
@
app
.
get
(
"/"
)
async
def
root
():
return
{
"message"
:
"Welcome to the Fish Identifications API!"
}
# @app.post("/net/image/prediction/")
# def getFishtype():
# rtt = get_net_image_prediction()
# return rtt
@
app
.
get
(
"/getResult"
)
async
def
send_image_get_prediction
(
request
:
Request
):
rtt
=
get_net_image_prediction
()
return
templates
.
TemplateResponse
(
"Saveimage.html"
,
{
"request"
:
request
,
"variable"
:
rtt
})
# async def send_image_get_prediction():
# rtt = get_net_image_prediction()
# return rtt
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