|
|
import gradio as gr |
|
|
import json |
|
|
from transformers import pipeline |
|
|
import warnings |
|
|
from transformers import ASTForAudioClassification, ASTFeatureExtractor |
|
|
|
|
|
warnings.filterwarnings("ignore") |
|
|
model = ASTForAudioClassification.from_pretrained("ATDI-Group/AST_finetuned_SIGIDwiki", subfolder='AST_finetuned_SIGIDwiki') |
|
|
feature_extractor = ASTFeatureExtractor.from_pretrained("ATDI-Group/AST_finetuned_SIGIDwiki", subfolder='AST_finetuned_SIGIDwiki') |
|
|
audio_classifier = pipeline("audio-classification", model=model, feature_extractor=feature_extractor) |
|
|
|
|
|
def analyze_signal(audio_path): |
|
|
if audio_path is None: |
|
|
return {"Error": "No audio file provided. Please upload a file."} |
|
|
|
|
|
print(f"Analysing audio file: {audio_path}...") |
|
|
try: |
|
|
acoustic_results = audio_classifier(audio_path, top_k=3) |
|
|
detected_sounds = {item['label']: round(item['score'], 2) for item in acoustic_results} |
|
|
|
|
|
holistic_understanding = { |
|
|
"Detected Sounds": detected_sounds, |
|
|
} |
|
|
return holistic_understanding |
|
|
except Exception as e: |
|
|
return {"Error": f"Could not process the audio file. Details: {str(e)}"} |
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=analyze_signal, |
|
|
inputs=gr.Audio(type="filepath", label="Upload your Audio File (.wav, .mp3)"), |
|
|
outputs=gr.JSON(label="Analysis Result"), |
|
|
title="Audio Spectrogram Transformer finetuned on SIGID wiki for Radio Signal Classification ", |
|
|
description=""" |
|
|
https://huggingface.co/ATDI-Group/AST_finetuned_SIGIDwiki |
|
|
""", |
|
|
examples=[["S5065-MSK.wav"]] |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch(debug=True) |
|
|
|