Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,34 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
output = pipe2(filepath)
|
15 |
-
return output["text"]
|
16 |
-
|
17 |
-
|
18 |
-
def transcribe_speech_russian(filepath):
|
19 |
-
if filepath is None:
|
20 |
-
gr.Warning("No audio found, please retry.")
|
21 |
-
return ""
|
22 |
-
output = pipe3(filepath)
|
23 |
-
return output["text"]
|
24 |
-
|
25 |
-
|
26 |
-
mic_transcribe_english = gr.Interface(
|
27 |
-
fn=transcribe_speech_english,
|
28 |
-
inputs=gr.Audio(sources="microphone",
|
29 |
-
type="filepath"),
|
30 |
-
outputs=gr.Textbox(label="Transcription",
|
31 |
-
lines=3),
|
32 |
-
allow_flagging="never")
|
33 |
-
|
34 |
-
|
35 |
-
mic_transcribe_russian = gr.Interface(
|
36 |
-
fn=transcribe_speech_russian,
|
37 |
-
inputs=gr.Audio(sources="microphone",
|
38 |
-
type="filepath"),
|
39 |
-
outputs=gr.Textbox(label="Transcription",
|
40 |
-
lines=3),
|
41 |
-
allow_flagging="never")
|
42 |
-
|
43 |
-
|
44 |
-
file_transcribe_english = gr.Interface(
|
45 |
-
fn=transcribe_speech_english,
|
46 |
-
inputs=gr.Audio(sources="upload",
|
47 |
-
type="filepath"),
|
48 |
-
outputs=gr.Textbox(label="Transcription",
|
49 |
-
lines=3),
|
50 |
-
allow_flagging="never",
|
51 |
-
)
|
52 |
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
type="filepath"),
|
58 |
-
outputs=gr.Textbox(label="Transcription",
|
59 |
-
lines=3),
|
60 |
-
allow_flagging="never",
|
61 |
-
)
|
62 |
|
|
|
63 |
|
64 |
with demo:
|
65 |
gr.TabbedInterface(
|
66 |
-
[
|
67 |
-
|
68 |
-
mic_transcribe_russian,
|
69 |
-
file_transcribe_russian],
|
70 |
-
["Transcribe Microphone English",
|
71 |
-
"Transcribe Audio File English",
|
72 |
-
"Transcribe Microphone Russian",
|
73 |
-
"Transcribe Audio File Russian"],
|
74 |
)
|
75 |
|
76 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
def launch(input_image):
|
6 |
+
out = depth_estimator(input_image)
|
7 |
|
8 |
+
# resize the prediction
|
9 |
+
prediction = F.interpolate(
|
10 |
+
out["predicted_depth"].unsqueeze(1),
|
11 |
+
size=input_image.size[::-1],
|
12 |
+
mode="bicubic",
|
13 |
+
align_corners=False,
|
14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# normalize the prediction
|
17 |
+
output = prediction.squeeze().numpy()
|
18 |
+
formatted = (output * 255 / np.max(output)).astype("uint8")
|
19 |
+
depth = Image.fromarray(formatted)
|
20 |
+
return depth
|
21 |
|
22 |
+
iface = gr.Interface(launch,
|
23 |
+
inputs=gr.Image(type='pil'),
|
24 |
+
outputs=gr.Image(type='pil'))
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
demo = gr.Blocks()
|
27 |
|
28 |
with demo:
|
29 |
gr.TabbedInterface(
|
30 |
+
[iface],
|
31 |
+
["iface"],
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
)
|
33 |
|
34 |
+
demo.launch(debug=True)
|