Questaaaa commited on
Commit
0e4149c
·
verified ·
1 Parent(s): 4cf9705

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 选择 Hugging Face 预训练模型
5
+ classifier = pipeline("image-classification", model="facebook/deit-base-distilled-patch16-224")
6
+
7
+ # 定义分类函数
8
+ def classify_image(image):
9
+ predictions = classifier(image)
10
+ return {pred["label"]: float(pred["score"]) for pred in predictions}
11
+
12
+ # 创建 Gradio 界面
13
+ demo = gr.Interface(fn=classify_image, inputs="image", outputs="label", title="Image Classification Demo")
14
+ demo.launch()