|
|
|
from ultralytics import YOLO |
|
|
|
model = YOLO('yolo11n-pose.pt') |
|
|
|
def poseImage(image): |
|
results = model(image) |
|
return results[0].plot() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
import speech_recognition as sr |
|
from PIL import Image |
|
|
|
|
|
def process_image(image): |
|
return image |
|
|
|
|
|
def process_audio(audio): |
|
recognizer = sr.Recognizer() |
|
with sr.AudioFile(audio) as source: |
|
audio_data = recognizer.record(source) |
|
try: |
|
text = recognizer.recognize_google(audio_data) |
|
return text |
|
except sr.UnknownValueError: |
|
return "Audio tidak dapat dikenali." |
|
except sr.RequestError as e: |
|
return f"Error dengan layanan pengenalan suara: {e}" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
gr.Markdown("## Aplikasi Input Gambar/Audio") |
|
|
|
with gr.Row(): |
|
input_type = gr.Radio(["Gambar", "Audio"], label="Pilih Jenis Input", value="Gambar") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
image_input = gr.Image(type='numpy', label="Masukkan Gambar", live=True, visible=False) |
|
audio_input = gr.Audio(sources="microphone", type="filepath", label="Masukkan Audio", visible=False) |
|
|
|
with gr.Column(): |
|
image_output = gr.Image(label="Hasil Gambar", visible=False) |
|
text_output = gr.Textbox(label="Hasil Audio", visible=False) |
|
|
|
|
|
def update_visibility(input_type): |
|
if input_type == "Gambar": |
|
return ( |
|
gr.update(visible=True), |
|
gr.update(visible=False), |
|
gr.update(visible=True), |
|
gr.update(visible=False), |
|
) |
|
elif input_type == "Audio": |
|
return ( |
|
gr.update(visible=False), |
|
gr.update(visible=True), |
|
gr.update(visible=False), |
|
gr.update(visible=True), |
|
) |
|
|
|
input_type.change( |
|
update_visibility, |
|
inputs=[input_type], |
|
outputs=[image_input, audio_input, image_output, text_output], |
|
) |
|
|
|
|
|
image_input.change(poseImage, inputs=[image_input], outputs=[image_output]) |
|
audio_input.change(process_audio, inputs=[audio_input], outputs=[text_output]) |
|
|
|
|
|
demo.launch() |
|
|