Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Initialize ASR and classifier pipelines
|
| 6 |
+
model_asr = "kairaamilanii/whisper-mind14-enUS"
|
| 7 |
+
model_class = "kairaamilanii/RoBERTa-minds-14-classifier-intent"
|
| 8 |
+
|
| 9 |
+
transcriber = pipeline(
|
| 10 |
+
"automatic-speech-recognition",
|
| 11 |
+
model=model_asr,
|
| 12 |
+
chunk_length_s=30,
|
| 13 |
+
device="cuda:0" if torch.cuda.is_available() else "cpu"
|
| 14 |
+
)
|
| 15 |
+
classifier = pipeline("text-classification", model=model_class)
|
| 16 |
+
|
| 17 |
+
intent_classes = {
|
| 18 |
+
0: 'abroad',
|
| 19 |
+
1: 'address',
|
| 20 |
+
2: 'app_error',
|
| 21 |
+
3: 'atm_limit',
|
| 22 |
+
4: 'balance',
|
| 23 |
+
5: 'business_loan',
|
| 24 |
+
6: 'card_issues',
|
| 25 |
+
7: 'cash_deposit',
|
| 26 |
+
8: 'direct_debit',
|
| 27 |
+
9: 'freeze',
|
| 28 |
+
10: 'latest_transactions',
|
| 29 |
+
11: 'joint_account',
|
| 30 |
+
12: 'high_value_payment',
|
| 31 |
+
13: 'pay_bill'
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Function to process audio
|
| 35 |
+
def process_audio(audio):
|
| 36 |
+
# Transcribe the audio
|
| 37 |
+
text_asr = transcriber(audio)['text']
|
| 38 |
+
# Classify the intent
|
| 39 |
+
intent_class = classifier(text_asr)
|
| 40 |
+
label_index = int(intent_class[0]['label'].split('_')[1])
|
| 41 |
+
intent_name = intent_classes.get(label_index, "Unknown")
|
| 42 |
+
return text_asr, intent_name
|
| 43 |
+
|
| 44 |
+
# Create Gradio interface
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=process_audio,
|
| 47 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 48 |
+
outputs=["text", "text"],
|
| 49 |
+
title="ASR and Intent Classification",
|
| 50 |
+
description="Upload an audio file to get transcription and intent classification."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
iface.launch()
|