Gradio
lastmod 2026-01-13created 2022-10-276 edits
Build a UI for your machine learning model in Python in 3 minutes
Categories
Projects using it
- Voice-Pro - Gradio WebUI supporting speech recognition, translation, and speech synthesis
Drawing a point on canvas click
import gradio as gr
import numpy as np
import cv2
# 기본 이미지를 생성합니다. (흰색 배경)
img = np.ones((500, 500, 3), dtype=np.uint8) * 255
# 클릭 이벤트 처리 함수
def draw_point(image, evt: gr.SelectData):
x, y = int(evt.index[0]), int(evt.index[1])
# 이미지를 numpy array로 변환
image = np.array(image, dtype=np.uint8)
# 클릭한 위치에 빨간 점 그리기
cv2.circle(image, (x, y), 10, (255, 0, 0), -1)
return image
# Gradio 인터페이스 구성
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
image = gr.Image(value=img, interactive=True, label="클릭하여 포인트 추가")
# 이미지 클릭 이벤트 처리
image.select(draw_point, inputs=[image], outputs=image)
# Gradio 앱 실행
demo.launch()
See also
Favorite site
Pages that link here