Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import json | |
import os | |
data_dict = {} | |
with open('./results_classification/file.json', 'r') as file: | |
data = json.load(file) | |
intents_dict = data | |
tokenizer = AutoTokenizer.from_pretrained("roberta-base") | |
model = AutoModelForSequenceClassification.from_pretrained("./results_classification/checkpoint-1890/") | |
def preprocess(text): | |
inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt") | |
return inputs | |
def postprocess(outputs): | |
logits = outputs.logits | |
predicted_labels = logits.argmax(dim=1).tolist() | |
return predicted_labels | |
def predict(text): | |
inputs = preprocess(text) | |
with torch.no_grad(): | |
outputs = model(**inputs) | |
predicted_labels = postprocess(outputs) | |
ans = intents_dict[predicted_labels[0]] | |
return ans | |
from transformers import pipeline | |
p = pipeline(model="openai/whisper-medium") | |
def transcribe(audio): | |
t = p(audio)['text'] | |
ans = predict(t) | |
return ans | |
get_intent = gr.Interface(fn = transcribe, | |
inputs=gr.Audio(source="microphone", type="filepath"), | |
outputs="text").launch() | |