Spaces:
Runtime error
Runtime error
File size: 993 Bytes
27df4ce c1f44fc 27df4ce c1f44fc 27df4ce 62446de 48f3abc 27df4ce f1f713b 27df4ce ddf0c20 a653ebc 27df4ce 04baa0a 27df4ce |
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 |
import re
import gradio as gr
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
device='cpu'
processor = AutoProcessor.from_pretrained("microsoft/git-base")
model = AutoModelForCausalLM.from_pretrained("nkasmanoff/git-planet").to(device)
def predict(image,max_length=64,device='cpu'):
pixel_values = processor(images=image, return_tensors="pt").to(device).pixel_values
generated_ids = model.generate(pixel_values=pixel_values, max_length=max_length)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_caption
input = gr.inputs.Image(label="Please upload a remote sensing image", type = 'pil', optional=True)
output = gr.outputs.Textbox(type="text",label="Captions")
title = "Satellite Image Captioning"
interface = gr.Interface(
fn=predict,
inputs = input,
theme="grass",
outputs=output,
title=title,
)
interface.launch(debug=True) |