Spaces:
Sleeping
Sleeping
| 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") | |