DCI / app.py
Araeynn's picture
Update app.py
9d18877 verified
raw
history blame contribute delete
705 Bytes
import gradio as gr
import asyncio
from huggingface_hub import AsyncInferenceClient
import os
hf = os.getenv("HF")
client = AsyncInferenceClient("google/siglip-base-patch16-224", token=hf)
def image_classifier(inp):
class_names = ["0", "1"]
inp.save("why.png")
sunflower_path = "why.png"
hf = os.getenv("HF")
r = asyncio.run(client.zero_shot_image_classification("why.png", candidate_labels=["mouth or teeth", "not mouth"]))
c = {}
a = r[0]["score"] + r[1]["score"]
c[r[0]["label"]] = r[0]["score"] / a
c[r[1]["label"]] = r[1]["score"] / a
return c
demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label")
demo.launch(debug=True)