Spaces:
Runtime error
Runtime error
Commit
·
b00b081
1
Parent(s):
91bd399
:wq
Browse files- .gitignore +1 -0
- app.py +26 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.venv
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from transformers import PaliGemmaForConditionalGeneration, AutoProcessor
|
| 5 |
+
|
| 6 |
+
TITLE = "E621 Tagger"
|
| 7 |
+
DESCRIPTION = "Tag images with E621 tags"
|
| 8 |
+
|
| 9 |
+
MODEL_ID = "estrogen/paligemma2-3b-e621-224"
|
| 10 |
+
|
| 11 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(MODEL_ID)
|
| 12 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
| 13 |
+
|
| 14 |
+
@spaces.GPU
|
| 15 |
+
def tag_image(image):
|
| 16 |
+
inputs = processor(images=image, text="<image>tag en", return_tensors="pt")
|
| 17 |
+
outputs = model.generate(**inputs)
|
| 18 |
+
return processor.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=tag_image,
|
| 22 |
+
inputs=gr.Image(type="pil"),
|
| 23 |
+
outputs=gr.Textbox(type="text"),
|
| 24 |
+
title=TITLE,
|
| 25 |
+
description=DESCRIPTION,
|
| 26 |
+
).launch()
|