Spaces:
Running
Running
File size: 1,146 Bytes
05be9b2 d083901 32e883d 05be9b2 35ceb6f d083901 f2b5de1 10e52d2 35ceb6f 7988f36 32c23d2 7988f36 2fe1915 378936b 7988f36 fb72456 f573715 10e52d2 d083901 10e52d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
from transformers import AutoProcessor, CLIPModel
# Charger le pipeline
model = CLIPModel.from_pretrained("patrickjohncyh/fashion-clip")
processor = AutoProcessor.from_pretrained("patrickjohncyh/fashion-clip")
# Définir la fonction pour la classification d'image avec du texte en entrée
def classify_image_with_text(text, image):
# Effectuer la classification d'image à l'aide du texte
keywords = text.split(',')
inputs = processor(
text=keywords, images=image, return_tensors="pt", padding=True
)
outputs = model(**inputs)
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
probs = logits_per_image.softmax(dim=1)
predicted_class_index = probs.argmax(dim=1).item()
predicted_label = keywords[predicted_class_index]
return predicted_label
# Créer l'interface Gradio avec l'API de Gradio Blocks
with gr.Interface(
fn=classify_image_with_text,
inputs=[gr.Textbox(lines=1, label="Prompt"), gr.Image(label="Image")],
outputs=gr.Textbox(label='Sortie de l\'API'),
title="SD Models"
) as iface:
iface.launch()
|