maika commited on
Commit
4ca6b93
·
verified ·
1 Parent(s): babb501

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Hugging Faceの画像分類パイプラインを使用(事前学習モデル)
5
+ classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
6
+
7
+ def classify_image(img):
8
+ results = classifier(img)
9
+ return {r["label"]: float(r["score"]) for r in results}
10
+
11
+ # Gradioインターフェースの定義
12
+ gr.Interface(
13
+ fn=classify_image,
14
+ inputs=gr.Image(type="pil"),
15
+ outputs=gr.Label(num_top_classes=3),
16
+ title="これは猫?犬?",
17
+ description="画像をアップロードすると画像分類モデルで判定します。"
18
+ ).launch()