mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-01 11:45:36 +08:00
* cleaning up launchable * removing launchables broken * deleted launchables * relaunch parameters * fixed close method * formatting * renamed blocks demos * creating a new blocks demo * added neural blocks demo * format backend * fixed naming bug i introduced
33 lines
665 B
Python
33 lines
665 B
Python
from transformers import pipeline
|
|
|
|
import gradio as gr
|
|
|
|
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
|
classifier = pipeline("text-classification")
|
|
|
|
|
|
def speech_to_text(speech):
|
|
text = asr(speech)["text"]
|
|
return text
|
|
|
|
|
|
def text_to_sentiment(text):
|
|
return classifier(text)[0]["label"]
|
|
|
|
|
|
demo = gr.Blocks()
|
|
|
|
with demo:
|
|
m = gr.Audio(type="filepath")
|
|
t = gr.Textbox()
|
|
l = gr.Label()
|
|
|
|
b1 = gr.Button("Recognize Speech")
|
|
b2 = gr.Button("Classify Sentiment")
|
|
|
|
b1.click(speech_to_text, inputs=m, outputs=t)
|
|
b2.click(text_to_sentiment, inputs=t, outputs=l)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|