Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-323
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
1
Merge Requests
1
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
2023-323
2023-323
Commits
0c606af4
Commit
0c606af4
authored
Sep 03, 2023
by
Kareshaan Logeswaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created It20109776 back end
parent
0c152b55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
api/disease.py
api/disease.py
+44
-0
No files found.
api/disease.py
0 → 100644
View file @
0c606af4
from
fastapi
import
FastAPI
,
File
,
UploadFile
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
FileResponse
,
HTMLResponse
import
uvicorn
import
numpy
as
np
from
io
import
BytesIO
from
PIL
import
Image
import
tensorflow
as
tf
app
=
FastAPI
()
MODEL
=
tf
.
keras
.
models
.
load_model
(
"../saved_models/Version34"
)
# Modify the CLASS_NAMES list to include additional details
CLASS_NAMES
=
[
"Brown Spot | Fungus Sphaerulina oryzina | Iprodione, Propiconazole, Azoxystrobin, Trifloxystrobin, Carbendazim "
,
"No Disease Detected - Healthy | Everything looks fine | Not required"
,
"Hispa | Armigera feed externally on leaf tissue | Carbofuran 3
%
CG 10 kg; emamectin benzoate 1.9 EC 170 ml; malathion 5 DP 10 kg; malathion 50 EC 460 ml."
,
"Leaf Blast| Fungus Magnaporthe oryzae. | Spray Carbendazim or Edifenphos @ 1.0 gm/lit , Pre-Tillering to Mid-Tillering: Light at 2 to 5
%
disease severities - Apply Edifenphos or Carbendazim @ 1.0 gm/lit."
]
def
read_file_as_image
(
data
)
->
np
.
ndarray
:
image
=
np
.
array
(
Image
.
open
(
BytesIO
(
data
)))
return
image
@
app
.
post
(
"/predictLeaf"
)
async
def
predict
(
file
:
UploadFile
=
File
(
...
)):
image
=
read_file_as_image
(
await
file
.
read
())
img_batch
=
np
.
expand_dims
(
image
,
0
)
predictions
=
MODEL
.
predict
(
img_batch
)
predicted_class
=
CLASS_NAMES
[
np
.
argmax
(
predictions
[
0
])]
confidence
=
np
.
max
(
predictions
[
0
])
return
{
'class'
:
predicted_class
,
'confidence'
:
float
(
confidence
)
}
@
app
.
get
(
"/"
)
async
def
get_index
():
with
open
(
'diseases.html'
,
'r'
)
as
f
:
return
HTMLResponse
(
content
=
f
.
read
(),
status_code
=
200
)
if
__name__
==
"__main__"
:
uvicorn
.
run
(
app
,
host
=
'localhost'
,
port
=
8000
)
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