Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import os | |
os.system("python -m pip install --upgrade pip") | |
os.system("pip install git+https://github.com/openai/whisper.git") | |
import whisper | |
title = "Zero-Shot Text Classification with Hugging Face" | |
description = "bart-large-mnli" | |
classifier = pipeline("zero-shot-classification", | |
model="facebook/bart-large-mnli") | |
# whisper model specification | |
asr_model = whisper.load_model("tiny") | |
# openai.api_key = os.environ["Openai_APIkey"] | |
# Transcribe function | |
def transcribe(audio_file): | |
print("Transcribing") | |
transcription = asr_model.transcribe(audio_file)["text"] | |
return transcription | |
#define a function to process your input and output | |
def zero_shot(doc, candidates): | |
given_labels = candidates.split(", ") | |
dictionary = classifier(doc, given_labels) | |
labels = dictionary['labels'] | |
scores = dictionary['scores'] | |
# print("here is the audio transcribed: ", aud) | |
return dict(zip(labels, scores)) | |
#example object | |
'''examples = [ | |
["TDC A/S provides communications and entertainment solutions in Denmark. It operates through Nuuday and TDC NET segments. The company designs, builds, and operates broadband and mobile networks; and provides technical support to customers and networks. It offers services, such as landline voice, TV and streaming, broadband, Internet and network, mobility, and other services. The company provides its products and services under the YouSee, Hiper, Telmore, Blockbuster, TDC Business, TDC Erhverv, Fullrate, NetDesign, and Relatel brands. It serves consumer and business customers. The company was founded in 1882 and is based in Copenhagen, Denmark. TDC A/S is a subsidiary of DK Telekommunikation ApS.", "Diversified Telecommunication Services, Wireless Telecommunication Services, Media, Entertainment, Interactive Media and Services"], | |
["Giddy Inc., doing business as Boxed Wholesale, offers online wholesale and retailing services. The company provides cleaning and laundry, kitchen, paper, skin care, hair care, and grocery products. Additionally, it offers diapers and organic products. Giddy Inc. was founded in 2013 and is based in Edison, New Jersey.", "Food and Staples Retailing, Beverages, Food Products, Household Products, Personal Products, Tobacco"], | |
["United Iron And Steel Manufacturing Company (P.L.C.) produces and sells iron and steel products in Jordan. It is also involved in trading scrap iron. The company was incorporated in 1992 and is headquartered in Amman, Jordan. United Iron And Steel Manufacturing Company (P.L.C.) is a subsidiary of Manaseer Group Corporation.", "Chemicals, Construction Materials, Containers and Packaging, Metals and Mining, Paper and Forest Products"] | |
] | |
''' | |
#create interface | |
with gr.Blocks() as gui: | |
#create input and output objects | |
#input object1 | |
input1 = gr.Textbox(label="Text") | |
#input object 2 | |
input2 = gr.Textbox(label="Labels") | |
#input 3 microphone | |
audio = gr.Audio( | |
label="Input Audio", | |
show_label=False, | |
source="microphone", | |
type="filepath" | |
) | |
transcribeButton = gr.Button("Transcribe") | |
runButton = gr.Button("Run") | |
transcribeButton.click(fn=transcribe,inputs=[audio], outputs=[input1]) | |
#output object | |
output = gr.Label(label="Output") | |
runButton.click(fn=zero_shot, inputs=[input1, input2], outputs=[output]) | |
#display the interface | |
gui.launch() |