|
import torch |
|
from PIL import Image |
|
from transformers import AutoModel, CLIPImageProcessor |
|
import gradio as gr |
|
|
|
|
|
model = AutoModel.from_pretrained( |
|
'OpenGVLab/InternVL2_5-1B', |
|
torch_dtype=torch.float32, |
|
low_cpu_mem_usage=True, |
|
trust_remote_code=True, |
|
use_flash_attn=False |
|
).eval() |
|
|
|
|
|
image_processor = CLIPImageProcessor.from_pretrained('OpenGVLab/InternVL2_5-1B') |
|
|
|
|
|
def process_image(image): |
|
try: |
|
|
|
image = image.convert('RGB') |
|
|
|
|
|
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values |
|
|
|
|
|
outputs = model(pixel_values) |
|
|
|
|
|
return f"Output Shape: {outputs.last_hidden_state.shape}" |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
|
|
demo = gr.Interface( |
|
fn=process_image, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Textbox(label="Model Output"), |
|
title="InternViT Demo", |
|
description="Upload an image to process it using the InternViT model from OpenGVLab." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch(server_name="0.0.0.0", server_port=7860) |