srt_example_llava.py 453 Bytes
Newer Older
Lianmin Zheng's avatar
Lianmin Zheng committed
1
2
3
4
5
6
7
8
9
import sglang as sgl


@sgl.function
def image_qa(s, image_path, question):
    s += sgl.user(sgl.image(image_path) + question)
    s += sgl.assistant(sgl.gen("answer"))


10
11
runtime = sgl.Runtime(model_path="liuhaotian/llava-v1.5-7b",
                      tokenizer_path="llava-hf/llava-1.5-7b-hf")
Lianmin Zheng's avatar
Lianmin Zheng committed
12
13
14
15
16
17
18
sgl.set_default_backend(runtime)


state = image_qa.run(image_path="images/cat.jpeg", question="What is this?")
print(state["answer"])

runtime.shutdown()