Spaces:
Sleeping
Sleeping
Commit
•
3f5ff90
1
Parent(s):
c629400
simple model
Browse files
app.py
CHANGED
@@ -1,66 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import tensorflow as tf
|
4 |
-
from transformers import pipeline, AutoModelForCTC, AutoTokenizer
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
-
|
10 |
-
trans = pipeline("automatic-speech-recognition", model=model, tokenizer=tokenizer)
|
11 |
|
12 |
def audio2text(audio):
|
13 |
text = trans(audio)["text"]
|
14 |
return text
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return classifier(text)[0]["label"]
|
22 |
-
|
23 |
-
|
24 |
-
# image_classification
|
25 |
-
inception_net = tf.keras.applications.MobileNetV2()
|
26 |
-
|
27 |
-
answer = requests.get("https://git.io/JJkYN")
|
28 |
-
labels = answer.text.split("\n")
|
29 |
-
|
30 |
-
def image_classification(inp):
|
31 |
-
inp = inp.reshape((-1,224,224,3))
|
32 |
-
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
33 |
-
prediction = inception_net.predict(inp).flatten()
|
34 |
-
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
35 |
-
return confidences
|
36 |
-
|
37 |
-
|
38 |
-
# demo
|
39 |
-
demo = gr.Blocks()
|
40 |
-
|
41 |
-
with demo:
|
42 |
-
gr.Markdown("This is the second demo with Blocks")
|
43 |
-
with gr.Tabs():
|
44 |
-
with gr.TabItem("Transcribe audio in Spanish"):
|
45 |
-
with gr.Row():
|
46 |
-
audio = gr.Audio(source="microphone", type="filepath")
|
47 |
-
transcription = gr.Textbox()
|
48 |
-
b1 = gr.Button("Transcribe")
|
49 |
-
|
50 |
-
with gr.TabItem("Sentiment analysis in Spanish"):
|
51 |
-
with gr.Row():
|
52 |
-
text = gr.Textbox()
|
53 |
-
label_sentiment = gr.Label()
|
54 |
-
b2 = gr.Button("Sentiment")
|
55 |
-
|
56 |
-
with gr.TabItem("Image classification"):
|
57 |
-
with gr.Row():
|
58 |
-
image=gr.Image(shape=(224,224))
|
59 |
-
label_image=gr.Label(num_top_classes=3)
|
60 |
-
b3 = gr.Button("Classify")
|
61 |
-
|
62 |
-
b1.click(audio2text, inputs = audio, outputs=transcription)
|
63 |
-
b2.click(text2sentiment, inputs=text, outputs=label_sentiment)
|
64 |
-
b3.click(image_classification, inputs=image, outputs=label_image)
|
65 |
-
|
66 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
+
# audio2text
|
5 |
+
trans = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
|
|
|
|
|
|
|
6 |
|
7 |
def audio2text(audio):
|
8 |
text = trans(audio)["text"]
|
9 |
return text
|
10 |
|
11 |
+
gr.Interface(
|
12 |
+
fn=transcribe,
|
13 |
+
inputs = [gr.Audio(source="microphone", type="filepath")],
|
14 |
+
outputs=["textbox"]
|
15 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|