Spaces:
Runtime error
Runtime error
gituser commited on
Commit ·
43d0388
1
Parent(s): 260801c
'hi'
Browse filesFiles changed (5)
- Helper_Functions.pyAdded+16
- __pycache__/Helper_Functions.cpython-39.pycAdded
- __pycache__/app.cpython-39.pycAdded
- app.pyAdded+44
- requirements.txtAdded+5
12345678910111213141516from keras.models import model_from_jsonimport joblibimport librosa
def load_model(): # Load model architecture from JSON file # with open('CNN_Raw.json', 'r') as json_file: # loaded_model_json = json_file.read() # loaded_model = model_from_json(loaded_model_json) # # # Load weights into the model # loaded_model.load_weights("CNN_Raw.h5")
loaded_model = joblib.load('pipeline.joblib')
return loaded_model1234567891011121314151617181920212223242526272829303132333435363738394041424344import gradio as grimport numpy as npimport librosafrom keras.models import model_from_json, load_modelfrom Helper_Functions import load_model, prepare_inputs
target_sr = 22050target_duration = 2 # in secondstarget_samples = target_sr * target_duration
model = load_model()
def transcribe(stream, new_chunk): sr, y = new_chunk y = y.astype(np.float32) y_resampled = librosa.resample(y = y, orig_sr = sr, target_sr = target_sr)
if stream is not None: stream = np.concatenate([stream, y_resampled]) else: stream = y_resampled # print(len(stream)) if len(stream) >= 44100: # Take the first 2 seconds of audio stream = stream[:target_samples] prediction = model.predict(stream.reshape(1,-1)) output = "all okay" if prediction > 0.5: output = "GUNSHOT DETECTED" return None, f"{output}"
return stream, ''
demo = gr.Interface( transcribe, ["state", gr.Audio(sources=["microphone"], streaming=True)], ["state", "text"], live=True,)
demo.launch()12345numpylibrosakerastensorflowjoblibHelper_Functions.pyAdded+16
__pycache__/Helper_Functions.cpython-39.pycAdded
__pycache__/app.cpython-39.pycAdded
app.pyAdded+44
requirements.txtAdded+5