Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-030
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
0
Merge Requests
0
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-030
2023-030
Commits
91a9deed
Commit
91a9deed
authored
Nov 07, 2023
by
Weerasooriya Liyana Arachchige Isuri Navoda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
fa0d54f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
+134
-0
weedDetection.js
weedDetection.js
+134
-0
No files found.
weedDetection.js
0 → 100644
View file @
91a9deed
import
'
./pred.css
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
Button
}
from
'
@mui/material
'
;
import
Box
from
'
@mui/material/Box
'
;
import
FormControl
from
'
@mui/material/FormControl
'
;
import
Paper
from
'
@mui/material/Paper
'
;
import
Typography
from
'
@mui/material/Typography
'
;
const
WeedDetection
=
()
=>
{
const
[
prediction
,
setPrediction
]
=
useState
(
''
);
const
[
file
,
setFile
]
=
useState
(
null
);
const
[
Imgfile
,
setFileImg
]
=
useState
(
null
);
const
handleFileChange
=
(
e
)
=>
{
setFile
(
e
.
target
.
files
[
0
]);
};
const
handleImgFileChange
=
(
e
)
=>
{
setFileImg
(
e
.
target
.
files
[
0
]);
};
const
handleImgPredict
=
async
()
=>
{
const
formData
=
new
FormData
();
formData
.
append
(
'
file
'
,
Imgfile
);
const
response
=
await
fetch
(
'
http://localhost:8000/predict
'
,
{
method
:
'
POST
'
,
body
:
formData
,
});
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
setPrediction
(
data
.
prediction
);
}
else
{
console
.
error
(
'
Failed to make a prediction.
'
);
}
};
const
handlePredict
=
async
()
=>
{
const
formData
=
new
FormData
();
formData
.
append
(
'
file
'
,
file
);
const
response
=
await
fetch
(
'
http://localhost:8000/video/detect-dense
'
,
{
method
:
'
POST
'
,
body
:
formData
,
});
if
(
response
.
ok
)
{
const
data
=
await
response
.
json
();
}
else
{
console
.
error
(
'
Failed to make a prediction.
'
);
}
};
return
(
<
div
className
=
"
app
"
style
=
{{
backgroundImage
:
'
url(/backg3.jpg)
'
,
backgroundRepeat
:
'
no-repeat
'
,
backgroundSize
:
"
contain
"
}}
>
<
div
className
=
"
centered-form
"
>
<
Paper
elevation
=
{
3
}
sx
=
{{
margin
:
'
20px
'
,
padding
:
'
20px
'
}}
>
<
div
>
<
h1
>
Weed
Prediction
<
/h1
>
<
input
type
=
"
file
"
onChange
=
{
handleImgFileChange
}
/
>
<
Box
sx
=
{{
m
:
1
}}
/
>
<
FormControl
sx
=
{{
m
:
1
,
minWidth
:
200
}}
size
=
"
medium
"
>
<
Button
onClick
=
{
handleImgPredict
}
variant
=
"
contained
"
style
=
{{
maxHeight
:
'
60px
'
,
minHeight
:
'
54px
'
}}
>
Check
<
/Button
>
<
/FormControl
>
<
/div
>
<
/Paper
>
<
Box
sx
=
{{
m
:
1
}}
/
>
<
Box
height
=
{
20
}
width
=
{
500
}
style
=
{{
display
:
'
flex
'
,
justifyContent
:
'
center
'
,
alignItems
:
'
center
'
,
height
:
'
8vh
'
,
margin
:
'
0 auto
'
,
}}
>
<
Paper
elevation
=
{
3
}
>
{
prediction
!==
''
&&
(
<
div
>
<
Box
sx
=
{{
m
:
1
}}
/
>
<
Typography
variant
=
"
body1
"
color
=
"
text.primary
"
align
=
"
center
"
style
=
{{
margin
:
'
20px
'
}}
>
Prediction
:
{
prediction
}
<
/Typography
>
<
/div
>
)}
<
/Paper
>
<
/Box
>
<
Paper
elevation
=
{
3
}
sx
=
{{
margin
:
'
20px
'
,
padding
:
'
20px
'
}}
>
<
div
>
<
h1
>
Dense
Area
Detect
<
/h1
>
<
input
type
=
"
file
"
onChange
=
{
handleFileChange
}
/
>
<
Box
sx
=
{{
m
:
1
}}
/
>
<
FormControl
sx
=
{{
m
:
1
,
minWidth
:
200
}}
size
=
"
medium
"
>
<
Button
onClick
=
{
handlePredict
}
variant
=
"
contained
"
style
=
{{
maxHeight
:
'
60px
'
,
minHeight
:
'
54px
'
}}
>
Check
<
/Button
>
<
/FormControl
>
<
/div
>
<
/Paper
>
<
Box
sx
=
{{
m
:
1
}}
/
>
<
Box
height
=
{
20
}
width
=
{
500
}
style
=
{{
display
:
'
flex
'
,
justifyContent
:
'
center
'
,
alignItems
:
'
center
'
,
height
:
'
8vh
'
,
margin
:
'
0 auto
'
,
}}
>
<
/Box
>
<
/div
>
<
/div
>
);
};
export
default
WeedDetection
;
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