Spaces:
Runtime error
Runtime error
| from transformers import pipeline | |
| import gradio as gr | |
| MODEL_NAME = "violence-audio-Recognition-666" | |
| HF_USER = "hemg" | |
| def prediction_function(input_file): | |
| repo_id = HF_USER + "/" + MODEL_NAME | |
| model = pipeline("audio-classification", model=repo_id) | |
| try: | |
| result = model(input_file) | |
| predictions = {} | |
| labels = [] | |
| for each_label in result: | |
| predictions[each_label["label"]] = each_label["score"] | |
| labels.append(each_label["label"]) | |
| result = predictions | |
| except: | |
| result = "no data provided!!" | |
| return result | |
| def create_interface(): | |
| interface = gr.Interface( | |
| fn=prediction_function, | |
| #inputs=gr.Audio(sources="upload", type="filepath"), | |
| #inputs=gr.Audio(sources="microphone", type="filepath"), | |
| inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title=MODEL_NAME, | |
| ) | |
| interface.launch() | |
| create_interface() |