image_to_text/app.py

35 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-03-29 08:59:06 +00:00
import gradio as gr
from transformers import AutoProcessor, AutoModelForCausalLM, AutoConfig
def inference(img):
pretrained_model_path = "git-large-coco"
processor = AutoProcessor.from_pretrained(pretrained_model_path)
model = AutoModelForCausalLM.from_pretrained(pretrained_model_path)
pixel_values = processor(images=img, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_caption
2023-03-30 03:33:11 +00:00
title = "Image to text:git-large-coco"
2023-03-29 08:59:06 +00:00
article = "<p style='text-align: center'><a href='https://github.com/bryandlee/animegan2-pytorch' target='_blank'>Github Repo Pytorch</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_animegan' alt='visitor badge'></center></p>"
examples=[['example_cat.jpg'],['Masahiro.png']]
2023-04-06 05:10:02 +00:00
with gr.Blocks() as demo:
gr.Markdown(
"""
# Image to text:git-large-coco
这是一个git-large-coco的Gradio Demo 上传你想要的图像或者点击下面的示例来加载它
""")
with gr.Row():
text_input = gr.Image()
text_output = gr.Textbox()
image_button = gr.Button("上传")
image_button.click(inference, inputs=text_input, outputs=text_output)
gr.Examples(examples, inputs=text_input)
2023-04-17 08:30:43 +00:00
demo.launch(server_name="0.0.0.0")