File size: 618 Bytes
0bafdb3
 
 
 
 
 
 
2942cde
2b81b7a
0bafdb3
 
 
 
 
 
 
 
 
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 = "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e"
pipe = pipeline("image-to-text", model=model_id, trust_remote_code=True)

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()