Spaces:
Runtime error
Runtime error
| 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() |