Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
import random | |
# 模擬辨識按鈕的回傳邏輯 | |
def fake_detect(image): | |
# 隨機回傳 "yap" 或 "not" | |
result = random.choice(["yap", "not"]) | |
return image, result | |
# 建立 Gradio 介面 | |
with gr.Blocks() as demo: | |
gr.Markdown("## 🦺 Helmet ") | |
gr.Markdown("請上傳一張圖片,然後點擊「辨識」按鈕模擬結果展示") | |
with gr.Row(): | |
with gr.Column(): | |
image_input = gr.Image(type="numpy", label="上傳圖片") | |
detect_button = gr.Button("辨識") | |
with gr.Column(): | |
image_output = gr.Image(type="numpy", label="推論結果") | |
result_label = gr.Textbox(label="辨識摘要", placeholder="結果") | |
detect_button.click(fn=fake_detect, inputs=image_input, outputs=[image_output, result_label]) | |
demo.launch() |