File size: 584 Bytes
3d32de6
 
 
 
 
be7703f
3d32de6
a7b729f
be7703f
3d32de6
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
import torch
from transformers import BitsAndBytesConfig, pipeline

# Load model directly


model_id = "marianna13/llava-phi-2-3b"
pipe = pipeline("image-to-text", model=model_id)

def generate_text(image):
    max_new_tokens = 200
    prompt = "USER: <image>\nWhat are the things I should be cautious about when I visit this place?\nASSISTANT:"
    outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
    return outputs[0]["generated_text"]

iface = gr.Interface(fn=generate_text, inputs=gr.inputs.Image(), outputs="text")
iface.launch()