File size: 938 Bytes
99df19f c282e28 957d892 6dadcd1 c282e28 6dadcd1 b966683 c282e28 b5f436b 234718c 50cb395 b966683 4cf03a8 234718c 05513ce 234718c 6dadcd1 957d892 b966683 |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoProcessor, AutoModel
repo_id = "OpenGVLab/InternVL2-1B"
# Load the tokenizer, processor, and model directly from the Hub
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True)
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
def analyze_image(image):
img = image.convert("RGB")
inputs = processor(images=img, text="describe this image", return_tensors="pt")
outputs = model.generate(**inputs)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
demo = gr.Interface(
fn=analyze_image,
inputs=gr.Image(type="pil"),
outputs="text",
title="Image Description using InternVL2-1B",
description="Upload an image and get a description generated by the InternVL2-1B model."
)
if __name__ == "__main__":
demo.launch() |