feat: gradio
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
|
| 4 |
model = YOLO('yolo11n-pose.pt')
|
|
@@ -7,11 +7,79 @@ def poseImage(image):
|
|
| 7 |
results = model(image)
|
| 8 |
return results[0].plot()
|
| 9 |
|
| 10 |
-
interface = gr.Interface(
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
|
| 4 |
model = YOLO('yolo11n-pose.pt')
|
|
|
|
| 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:
|
| 31 |
+
audio_data = recognizer.record(source)
|
| 32 |
+
try:
|
| 33 |
+
text = recognizer.recognize_google(audio_data)
|
| 34 |
+
return text
|
| 35 |
+
except sr.UnknownValueError:
|
| 36 |
+
return "Audio tidak dapat dikenali."
|
| 37 |
+
except sr.RequestError as e:
|
| 38 |
+
return f"Error dengan layanan pengenalan suara: {e}"
|
| 39 |
+
|
| 40 |
+
# Interface Gradio
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
with gr.Row():
|
| 43 |
+
gr.Markdown("## Aplikasi Input Gambar/Audio")
|
| 44 |
+
|
| 45 |
+
with gr.Row():
|
| 46 |
+
input_type = gr.Radio(["Gambar", "Audio"], label="Pilih Jenis Input", value="Gambar")
|
| 47 |
+
|
| 48 |
+
with gr.Row():
|
| 49 |
+
with gr.Column():
|
| 50 |
+
image_input = gr.Image(type='numpy', label="Masukkan Gambar", live=True, visible=False)
|
| 51 |
+
audio_input = gr.Audio(sources="microphone", type="filepath", label="Masukkan Audio", visible=False)
|
| 52 |
+
|
| 53 |
+
with gr.Column():
|
| 54 |
+
image_output = gr.Image(label="Hasil Gambar", visible=False)
|
| 55 |
+
text_output = gr.Textbox(label="Hasil Audio", visible=False)
|
| 56 |
+
|
| 57 |
+
# Fungsi untuk mengatur visibilitas berdasarkan jenis input
|
| 58 |
+
def update_visibility(input_type):
|
| 59 |
+
if input_type == "Gambar":
|
| 60 |
+
return (
|
| 61 |
+
gr.update(visible=True),
|
| 62 |
+
gr.update(visible=False),
|
| 63 |
+
gr.update(visible=True),
|
| 64 |
+
gr.update(visible=False),
|
| 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()
|