Johnny0619 commited on
Commit
093c2a6
·
verified ·
1 Parent(s): 788950c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -5,27 +5,22 @@ from transformers import pipeline
5
  classifier = pipeline("image-classification", model="Kaludi/food-category-classification-v2.0")
6
 
7
  def predict_food(image):
8
- # カメラが切り替わる瞬間など、画像が空の時は何もしない
9
  if image is None:
10
  return None
11
-
12
- # 推論実行
13
  predictions = classifier(image)
14
-
15
- # 結果を返す
16
  return {p["label"]: p["score"] for p in predictions}
17
 
18
  # アプリ設定
19
  demo = gr.Interface(
20
  fn=predict_food,
21
- # 【変更1sources=["webcam"] でカメラ専用にする
22
- # 【変更点2】 streaming=True 像を連続送信するモードにす
23
- inputs=gr.Image(sources=["webcam"], streaming=True),
24
  outputs=gr.Label(num_top_classes=3, label="リアルタイム判定"),
25
- # 【変更点3】 live=True で「送信ボタン」を消して自動更新にす
26
  live=True,
27
  title="リアルタイム AI 料理判定",
28
- description="カメラに料理を映すと、リアルタイムでAIが判定ます。"
29
  )
30
 
31
  if __name__ == "__main__":
 
5
  classifier = pipeline("image-classification", model="Kaludi/food-category-classification-v2.0")
6
 
7
  def predict_food(image):
 
8
  if image is None:
9
  return None
 
 
10
  predictions = classifier(image)
 
 
11
  return {p["label"]: p["score"] for p in predictions}
12
 
13
  # アプリ設定
14
  demo = gr.Interface(
15
  fn=predict_food,
16
+ # 【修正点】 streaming=True を削除しました。
17
+ # これにより「動画」としてはなく「パラパラ漫画」のように画像を連続送信するなり、負荷が下がりま
18
+ inputs=gr.Image(sources=["webcam"], label="カメラ"),
19
  outputs=gr.Label(num_top_classes=3, label="リアルタイム判定"),
20
+ # live=True しておくと、画像が変わるたび判定が走りま
21
  live=True,
22
  title="リアルタイム AI 料理判定",
23
+ description="カメラに料理を映してください。"
24
  )
25
 
26
  if __name__ == "__main__":