-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfracture_tooth_detection.py
57 lines (49 loc) · 2.66 KB
/
fracture_tooth_detection.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
import streamlit as st
import os
import PIL
import cv2
import secrets
import pymongo
import io
import cv2
from mongoengine import Document
from mongoengine import FileField
from mongoengine import *
connect(host="mongodb+srv://adithya_admin:YlV1pML2mjkP2LMb@dental-diagnosis.xevq3.mongodb.net/dental_diagnosis?retryWrites=true&w=majority")
class FractureDetector(Document):
# by default collection_name is 'fs'
# you can use collection_name parameter to set the name of the collection
# use collection_name like this: FileField(collection_name='images')
_id = StringField(required=True)
description = StringField(required=True)
image_fracture = FileField()
def write():
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Fracture Tooth Detection By A.Adithya Sherwood IX-E")
st.subheader('Disclaimer: Please check with your local specialized dentist, if you are in doubt please try atleast twice.')
uploaded_file = st.file_uploader("Choose an image", type="jpg")
conf_score = st.slider('Please Choose A Confidence Value',0.1,1.0,0.05)
option = st.selectbox(
'Please Select a Model',
('Yolo-v5', 'Efficient Det D4'))
if uploaded_file is not None:
file_random = secrets.token_hex(4)
image = PIL.Image.open(uploaded_file)
image = image.resize((416,416))
image.save(f'./Test_Fracture{file_random}.jpg')
#TODO White List IP From Anywhere DONE!
image_frac = open(f'./Test_Fracture{file_random}.jpg','rb')
fracture_form = FractureDetector(_id = secrets.token_hex(4),description='Uploaded Fracture Image',image_fracture=image_frac)
fracture_form.save()
st.image(image, caption='Uploaded Image.', use_column_width=True)
st.write("")
if option == "Yolo-v5":
os.system(f"python3 detect.py --weights './weights/best.pt' --img 416 --conf {str(conf_score)} --source ./Test_Fracture{file_random}.jpg --output ./inference/output ")
image_pred = PIL.Image.open(f'./inference/output/Test_Fracture{file_random}.jpg')
elif option == "Efficient Det D4":
os.system(f"python3 detect.py --weights './weights/best (1).pt' --img 416 --conf {str(conf_score)} --source ./Test_Fracture{file_random}.jpg --output ./inference/output ")
image_pred = PIL.Image.open(f'./inference/output/Test_Fracture{file_random}.jpg')
image_frac_output = open(f'./inference/output/Test_Fracture{file_random}.jpg','rb')
fracture_form_out = FractureDetector(_id = secrets.token_hex(4),description='Predicted Fracture Image',image_fracture=image_frac_output)
fracture_form_out.save()
st.image(image_pred, caption='Predictions.', use_column_width=True)