mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
9b42ba8f10
* changes * changes * revert changes * changes * add changeset * notebooks script * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
30 lines
729 B
Python
30 lines
729 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"] # type: ignore
|
|
return text
|
|
|
|
def text_to_sentiment(text):
|
|
return classifier(text)[0]["label"] # type: ignore
|
|
|
|
demo = gr.Blocks()
|
|
|
|
with demo:
|
|
audio_file = gr.Audio(type="filepath")
|
|
text = gr.Textbox()
|
|
label = gr.Label()
|
|
|
|
b1 = gr.Button("Recognize Speech")
|
|
b2 = gr.Button("Classify Sentiment")
|
|
|
|
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
|
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|