Spaces:
Sleeping
Sleeping
File size: 1,980 Bytes
a1404b6 3af45a2 d91b12e adf7a37 4a72c7a 87bc019 4a72c7a ec21657 4a72c7a a339abc 0e256ab 5ffb360 d91b12e c6f031f 6aa6eed ce358bf c6f031f 34705d2 c6f031f 0a0025a c6f031f |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import cv2
import streamlit as st
from fastai.vision.all import *
import base64
from streamlit_webrtc import webrtc_streamer
import av
import time
def video_frame_callback(frame):
#time.sleep(1)
return frame
webrtc_streamer(key="example",rtc_configuration={ # Add this config
"iceServers": [
{
"urls": "stun:stun.relay.metered.ca:80",
},
{
"urls": "turn:a.relay.metered.ca:80",
"username": "1569e470fe2a2afdb9e2b963",
"credential": "EG59c3tmBQzU7mMw",
},
{
"urls": "turn:a.relay.metered.ca:80?transport=tcp",
"username": "1569e470fe2a2afdb9e2b963",
"credential": "EG59c3tmBQzU7mMw",
},
{
"urls": "turn:a.relay.metered.ca:443",
"username": "1569e470fe2a2afdb9e2b963",
"credential": "EG59c3tmBQzU7mMw",
},
{
"urls": "turn:a.relay.metered.ca:443?transport=tcp",
"username": "1569e470fe2a2afdb9e2b963",
"credential": "EG59c3tmBQzU7mMw",
},
]
})
st.markdown('<h1 style="color:black;">BDI Image classification model</h1>', unsafe_allow_html=True)
learn = load_learner('export (5).pkl')
upload = st.file_uploader('Insert image for classification', type=['png','jpg'])
c1, c2= st.columns(2)
def autoplay_audio(file_path: str):
with open(file_path, "rb") as f:
data = f.read()
b64 = base64.b64encode(data).decode()
md = f"""
<audio controls autoplay="true">
<source src="data:audio/mp3;base64,{b64}" type="audio/mp3">
</audio>
"""
st.markdown(
md,
unsafe_allow_html=True,
)
if upload is not None:
im= Image.open(upload)
c1.header('Input Image')
c1.image(im)
pred, idx, probs = learn.predict(im)
c2.header('Output')
c2.subheader('Predicted class :')
c2.write(pred)
if pred == "Dog Destroying Stuff":
autoplay_audio("B1eckLSj.mp3")
|