AmitPress commited on
Commit
874c83a
·
1 Parent(s): 11e0195
Files changed (3) hide show
  1. app.py +35 -0
  2. requirements.txt +7 -0
  3. resource/twenty-eight-first.pt +3 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ import streamlit as st
3
+ from PIL import Image
4
+ import openai
5
+ from huggingface_hub import Repository
6
+
7
+ repo = Repository("AmitPress/snake-detection")
8
+ secret_key = repo.get_secret('openapi')
9
+ openai.api_key(secret_key)
10
+ model = YOLO('resource/twenty-eight-first.pt')
11
+
12
+ 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']
13
+ col1, col2 = st.columns([2,1])
14
+
15
+ col1.title('Snake Detection System')
16
+
17
+ photo = col2.file_uploader('Upload an Image (JPEG)', type='jpg')
18
+ if photo:
19
+ col2.success('Successfully Uploaded')
20
+ col1.image(photo)
21
+ image = Image.open(photo)
22
+ try:
23
+ bx = model(image)[0].boxes[0]
24
+ col1.write(f"Result: {(classes[int(bx.cls[0])])}")
25
+ txt = classes[int(bx.cls[0])]
26
+ genus, species = txt.split(' ')
27
+ venomousity = openai.Completion.create(engine="text-davinci-003", prompt=f"Is {genus} {species} is venomous? if venomous just say venomous otherwise say nonvenomous", max_tokens=50)
28
+ desc = openai.Completion.create(engine="text-davinci-003", prompt=f"Give a short description of {genus} {species}", max_tokens=500)
29
+ col1.write(venomousity)
30
+ col1.write(desc)
31
+ except:
32
+ col1.write(f"Error: There might be some network issue")
33
+ else:
34
+ col1.write('Please Upload an Image of a Snake')
35
+ col1.write('Result will be shown as soon as the image is uploaded')
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ ultralytics
3
+ pillow
4
+ requests
5
+ bs4
6
+ openai
7
+ huggingface_hub
resource/twenty-eight-first.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebd0d3da901697d7db68e3e9cbac0c29be0566db98cb997b0b5a70cc1a4ee661
3
+ size 52038944