import gradio as gr | |
from transformers import pipeline | |
# 选择 Hugging Face 预训练模型 | |
classifier = pipeline("feature-extraction", model="facebook/deit-base-distilled-patch16-224") | |
# 定义分类函数 | |
def classify_image(image): | |
predictions = classifier(image) | |
return {"feature_vector": predictions[0]} # 返回特征向量 | |
# 创建 Gradio 界面 | |
demo = gr.Interface(fn=classify_image, inputs="image", outputs="text", title="Image Classification Demo") | |
demo.launch() | |