File size: 1,017 Bytes
1bde739
 
 
 
 
 
 
 
 
 
 
 
788950c
1bde739
 
093c2a6
 
 
788950c
093c2a6
788950c
 
093c2a6
1bde739
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import pipeline

# モデルの読み込み
classifier = pipeline("image-classification", model="Kaludi/food-category-classification-v2.0")

def predict_food(image):
    if image is None:
        return None
    predictions = classifier(image)
    return {p["label"]: p["score"] for p in predictions}

# アプリ設定
demo = gr.Interface(
    fn=predict_food,
    # 【修正点】 streaming=True を削除しました。
    # これにより「動画」としてではなく「パラパラ漫画」のように画像を連続送信する形になり、負荷が下がります。
    inputs=gr.Image(sources=["webcam"], label="カメラ"),
    outputs=gr.Label(num_top_classes=3, label="リアルタイム判定"),
    # live=True にしておくと、画像が変わるたびに判定が走ります
    live=True,
    title="リアルタイム AI 料理判定",
    description="カメラに料理を映してください。"
)

if __name__ == "__main__":
    demo.launch()