Spaces:
Sleeping
Sleeping
maika
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 6 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
+
|
| 8 |
+
def generate_caption(image):
|
| 9 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 10 |
+
out = model.generate(**inputs)
|
| 11 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 12 |
+
return caption
|
| 13 |
+
|
| 14 |
+
gr.Interface(fn=generate_caption,
|
| 15 |
+
inputs=gr.Image(type="pil"),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="η»εγγ£γγ·γ§γ³ηζ",
|
| 18 |
+
description="γ’γγγγΌγγγγη»εγ«ε―Ύγγ¦γγ£γγ·γ§γ³γθͺεηζγγΎγ"
|
| 19 |
+
).launch()
|