File size: 1,691 Bytes
0be3da5
 
 
a312062
 
726b078
0be3da5
726b078
0be3da5
 
 
 
 
 
 
 
 
 
 
 
a312062
f30494f
a312062
 
 
 
0be3da5
f30494f
71a9781
 
 
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
from ultralytics import YOLO
import streamlit as st
from PIL import Image
import requests
from bs4 import BeautifulSoup
model = YOLO('resource/twenty-eight-first.pt')

classes = ['Ahaetulla nasuta', 'Ahaetulla prasina', 'Boiga cynodon', 'Boiga multomaculata', 'Bungarus caeruleus', 'Bungarus fasciatus', 'Chrysopelea ornata', 'Coelognathus radiatus', 'Daboia russelii', 'Dendrelaphis pictus', 'Dendrelaphis tristis', 'Echis carinatus', 'Fowlea piscator', 'Hydrophis platurus', 'Indotyphlops braminus', 'Laticauda colubrina', 'Lycodon aulicus', 'Malayopython reticulatus', 'Naja kaouthia', 'Naja naja', 'Oreocryptophis porphyraceus', 'Psammodynastes pulverulentus', 'Ptyas korros', 'Ptyas mucosa', 'Python bivittatus', 'Rhabdophis subminiatus', 'Trimeresurus albolabris', 'Xenochrophis piscator']
col1, col2 = st.columns([2,1])

col1.title('Snake Detection System')

photo = col2.file_uploader('Upload an Image (JPEG)', type='jpg')
if photo:
    col2.success('Successfully Uploaded')
    col1.image(photo)
    image = Image.open(photo)
    try:
        bx = model(image)[0].boxes[0]
        col1.write(f"Result: {(classes[int(bx.cls[0])])}")
        txt = classes[int(bx.cls[0])]
        genus, species = txt.split(' ')
        data = requests.get(f'https://reptile-database.reptarium.cz/species?genus={genus}&species={species}')
        bs = BeautifulSoup(data.content, 'html.parser')
        desc = bs.find('td', string='Comment').find_next_sibling('td').text
        col1.write(desc)
    except:
        col1.write(f"Error: There might be some network issue")
else:
    col1.write('Please Upload an Image of a Snake')
    col1.write('Result will be shown as soon as the image is uploaded')