Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from turtle import title
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def shot(image, labels_text):
|
| 12 |
+
PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
|
| 13 |
+
labels = labels_text.split(",")
|
| 14 |
+
res = pipe(images=PIL_image,
|
| 15 |
+
candidate_labels=labels,
|
| 16 |
+
)
|
| 17 |
+
return {dic["label"]: dic["score"] for dic in res}
|
| 18 |
+
|
| 19 |
+
iface = gr.Interface(shot,
|
| 20 |
+
["image", "text"],
|
| 21 |
+
"label",
|
| 22 |
+
|
| 23 |
+
description="Placer une image",
|
| 24 |
+
title="Powo Class")
|
| 25 |
+
|
| 26 |
+
iface.launch()
|