Create app.py
Browse files
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()
|