File size: 1,205 Bytes
fe8f93b ce16dc1 4a3ec14 f446279 ce16dc1 b75b060 ce16dc1 fe8f93b |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<!DOCTYPE html>
<html>
<head>
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
</head>
<body>
<gradio-lite>
<gradio-requirements>
transformers_js_py
</gradio-requirements>
<gradio-file name="app.py" entrypoint>
from transformers_js import import_transformers_js, as_url
import gradio as gr
transformers = await import_transformers_js()
pipeline = transformers.pipeline
pipe = await pipeline('zero-shot-image-classification')
async def classify(image, classes):
if not image:
return {}
classes = [x for c in classes.split(",") if (x := c.strip())]
if not classes:
return {}
data = await pipe(as_url(image), classes)
result = {item['label']: round(item['score'], 2) for item in data}
return result
demo = gr.Interface(
classify,
[
gr.Image(label="Input image", sources=["webcam"], type="filepath", streaming=True),
gr.Textbox(label="Classes separated by commas")
],
gr.Label(),
live=True
)
demo.launch()
</gradio-file>
</gradio-lite>
</body>
</html>
|