feat: app
Browse files
app.py
CHANGED
@@ -1,30 +1,13 @@
|
|
1 |
-
|
2 |
from ultralytics import YOLO
|
|
|
3 |
|
4 |
model = YOLO('yolo11n-pose.pt')
|
5 |
|
6 |
-
def
|
7 |
results = model(image)
|
8 |
return results[0].plot()
|
9 |
|
10 |
-
# interface = gr.Interface(
|
11 |
-
# fn=poseImage,
|
12 |
-
# inputs=gr.Image(streaming=True),
|
13 |
-
# outputs=gr.Image(),
|
14 |
-
# live=True
|
15 |
-
# )
|
16 |
-
|
17 |
-
# interface.launch()
|
18 |
-
|
19 |
-
import gradio as gr
|
20 |
-
import speech_recognition as sr
|
21 |
-
from PIL import Image
|
22 |
-
|
23 |
-
# Fungsi untuk memproses gambar
|
24 |
-
def process_image(image):
|
25 |
-
return image # Mengembalikan gambar yang sama
|
26 |
-
|
27 |
-
# Fungsi untuk memproses audio
|
28 |
def process_audio(audio):
|
29 |
recognizer = sr.Recognizer()
|
30 |
with sr.AudioFile(audio) as source:
|
@@ -37,49 +20,32 @@ def process_audio(audio):
|
|
37 |
except sr.RequestError as e:
|
38 |
return f"Error dengan layanan pengenalan suara: {e}"
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
with gr.Blocks() as demo:
|
42 |
with gr.Row():
|
43 |
-
gr.Markdown("
|
44 |
-
|
45 |
-
with gr.Row():
|
46 |
-
input_type = gr.Radio(["Gambar", "Audio"], label="Pilih Jenis Input", value="Gambar")
|
47 |
-
|
48 |
with gr.Row():
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
elif input_type == "Audio":
|
67 |
-
return (
|
68 |
-
gr.update(visible=False),
|
69 |
-
gr.update(visible=True),
|
70 |
-
gr.update(visible=False),
|
71 |
-
gr.update(visible=True),
|
72 |
-
)
|
73 |
-
|
74 |
-
input_type.change(
|
75 |
-
update_visibility,
|
76 |
-
inputs=[input_type],
|
77 |
-
outputs=[image_input, audio_input, image_output, text_output],
|
78 |
-
)
|
79 |
-
|
80 |
-
# Menghubungkan input dengan output
|
81 |
-
image_input.change(poseImage, inputs=[image_input], outputs=[image_output])
|
82 |
-
audio_input.change(process_audio, inputs=[audio_input], outputs=[text_output])
|
83 |
|
84 |
-
# Menjalankan aplikasi
|
85 |
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
from ultralytics import YOLO
|
3 |
+
import speech_recognition as sr
|
4 |
|
5 |
model = YOLO('yolo11n-pose.pt')
|
6 |
|
7 |
+
def proses_image(image):
|
8 |
results = model(image)
|
9 |
return results[0].plot()
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def process_audio(audio):
|
12 |
recognizer = sr.Recognizer()
|
13 |
with sr.AudioFile(audio) as source:
|
|
|
20 |
except sr.RequestError as e:
|
21 |
return f"Error dengan layanan pengenalan suara: {e}"
|
22 |
|
23 |
+
def update_visibility(input):
|
24 |
+
if input == "Gambar":
|
25 |
+
return gr.Row(visible=True), gr.Row(visible=False)
|
26 |
+
elif input == "Audio":
|
27 |
+
return gr.Row(visible=False), gr.Row(visible=True)
|
28 |
+
|
29 |
with gr.Blocks() as demo:
|
30 |
with gr.Row():
|
31 |
+
gr.Markdown("# Multimodal America Sign Language")
|
|
|
|
|
|
|
|
|
32 |
with gr.Row():
|
33 |
+
input = gr.Radio(["Gambar", "Audio"], value="Gambar", label="Pilih mode:")
|
34 |
+
with gr.Row(visible=True) as gambar:
|
35 |
+
gr.Interface(
|
36 |
+
fn=proses_image,
|
37 |
+
inputs=gr.Image(streaming=True),
|
38 |
+
outputs=gr.Image(),
|
39 |
+
live=True
|
40 |
+
)
|
41 |
+
with gr.Row(visible=False) as audio:
|
42 |
+
gr.Interface(
|
43 |
+
fn=process_audio,
|
44 |
+
inputs=gr.Audio(sources="microphone", type="filepath", streaming=True),
|
45 |
+
outputs=gr.Textbox(),
|
46 |
+
live=True
|
47 |
+
)
|
48 |
+
|
49 |
+
input.change(update_visibility, inputs=[input], outputs=[gambar, audio])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
|
|
51 |
demo.launch()
|