Spaces:
Runtime error
Runtime error
File size: 1,290 Bytes
27df4ce c1f44fc 27df4ce 50526d9 a40cc28 27df4ce 62446de 9e79a2c 27df4ce a40cc28 27df4ce 073c8a9 27df4ce 529bd38 073c8a9 27df4ce 50526d9 b943b58 a653ebc 27df4ce 26177cc 4c16cd7 27df4ce c9b287c 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 34 35 36 37 38 39 |
import re
import gradio as gr
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
import spacy
device='cpu'
processor = AutoProcessor.from_pretrained("microsoft/git-base")
model = AutoModelForCausalLM.from_pretrained("nkasmanoff/sky-scribe").to(device)
def predict(image,max_length=50,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 an image", type = 'pil', optional=True)
output = gr.outputs.Textbox(type="text",label="Captions")
title = "Satellite Image Captioning"
description = "Provide an image, receive a description of the event with predictions about location, date, observing instrument, and possible event type. For best results, please consider using images only from NASA Earth."
interface = gr.Interface(
fn=predict,
inputs = input,
theme="grass",
outputs=output,
title=title,
description=description,
flagging_callback=gr.SimpleCSVLogger()
)
interface.launch(debug=True) |