File size: 3,442 Bytes
708f4c5
 
26ca121
 
427b3c7
 
708f4c5
 
 
 
 
 
 
427b3c7
 
 
0efcdee
427b3c7
 
 
 
 
 
 
 
708f4c5
d4a97c9
708f4c5
 
 
 
d4a97c9
708f4c5
 
 
 
 
 
 
33d39e0
 
 
 
 
 
 
 
 
708f4c5
 
d4a97c9
708f4c5
 
 
 
 
 
 
 
 
 
d4a97c9
708f4c5
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
from transformers import pipeline
import os
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, aud):
    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))

#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"
                )

#output object
output = gr.Label(label="Output")

#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
gui = gr.Interface(title=title,
                   description=description,
                   fn=zero_shot,
                   inputs=[input1, input2, audio],
                   outputs=[output],
                   examples=examples)

#display the interface
gui.launch()