File size: 736 Bytes
5127ddf
570fb8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5127ddf
 
570fb8b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Load the Hugging Face model
pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-1B", trust_remote_code=True)

# Define a function that will run the pipeline with user inputs
def run_internvl(image, prompt):
    messages = [{"role": "user", "content": prompt}]
    return pipe(image=image, messages=messages)

# Create the Gradio interface
interface = gr.Interface(
    fn=run_internvl,
    inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Ask something about the image...")],
    outputs="text",
    title="InternVL2 Image + Text Assistant",
    description="Upload an image and ask a question or give a prompt."
)

# Launch the app
interface.launch()