Views
No views yet

1from transformers import AutoTokenizer, AutoModelForCausalLM
2from transformers.generation import GenerationConfig
3
4tokenizer = AutoTokenizer.from_pretrained("AgoraX/Lumixion-e1-70k-fncall-qlora",trust_remote_code=True)
5
6model = AutoModelForCausalLM.from_pretrained(
7 "AgoraX/Lumixion-e1-70k-fncall-qlora", # path to the output directory
8 device_map="cuda",
9 trust_remote_code=True
10).eval()
11
12
13
14# 1st dialogue turn
15query = tokenizer.from_list_format([
16 {'image': 'https://images.rawpixel.com/image_800/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIzLTA4L3Jhd3BpeGVsX29mZmljZV8xNV9waG90b19vZl9hX2RvZ19ydW5uaW5nX3dpdGhfb3duZXJfYXRfcGFya19lcF9mM2I3MDQyZC0zNWJlLTRlMTQtOGZhNy1kY2Q2OWQ1YzQzZjlfMi5qcGc.jpg'}, # Either a local path or an url
17 {'text': "What are the objects in the image? What animals are present? Are there any people in the image?"},
18])
19print("sending model to chat")
20response, history = model.chat(tokenizer, query=query, history=None)
21print(response)
22
23## How to Get Started with the Model[FUNCTION CALL]
{{
'type': 'object',
'properties': {{
'objects': {{
'type': 'array',
'description': 'The objects present in the image.',
'items': {{
'type': 'string',
'enum': ['dog', 'person', 'tree', 'path', 'sun']
}}
}},
'animals': {{
'type': 'array',
'description': 'The animals present in the image.',
'items': {{
'type': 'string',
'enum': ['dog']
}}
}},
'people': {{
'type': 'boolean',
'description': 'Whether there are people in the image.',
'enum': [true]
}}
}}
}}
[EXPECTED OUTPUT]
{{
'objects': ['dog', 'person', 'tree', 'path', 'sun'],
'animals': ['dog'],
'people': true
}}
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers.generation import GenerationConfigtokenizer = AutoTokenizer.from_pretrained("qwen/Qwen-VL-Chat",trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"MODEL_PATH_HERE", # path to the output directory
device_map="cuda",
trust_remote_code=True
).eval()#model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-VL-Chat", trust_remote_code=True)
# 1st dialogue turn
query = tokenizer.from_list_format([
{'image': 'https://images.rawpixel.com/image_800/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIzLTA4L3Jhd3BpeGVsX29mZmljZV8xNV9waG90b19vZl9hX2RvZ19ydW5uaW5nX3dpdGhfb3duZXJfYXRfcGFya19lcF9mM2I3MDQyZC0zNWJlLTRlMTQtOGZhNy1kY2Q2OWQ1YzQzZjlfMi5qcGc.jpg'}, # Either a local path or an url
{'text': "What are the objects in the image? What animals are present? Are there any people in the image?"},
])
print("sending model to chat")
response, history = model.chat(tokenizer, query=query, history=None)
print(response)[FUNCTION CALL]
{{
'type': 'object',
'properties': {{
'objects': {{
'type': 'array',
'description': 'The objects present in the image.',
'items': {{
'type': 'string',
'enum': ['dog', 'person', 'tree', 'path', 'sun']
}}
}},
'animals': {{
'type': 'array',
'description': 'The animals present in the image.',
'items': {{
'type': 'string',
'enum': ['dog']
}}
}},
'people': {{
'type': 'boolean',
'description': 'Whether there are people in the image.',
'enum': [true]
}}
}}
}}
[EXPECTED OUTPUT]
{{
'objects': ['dog', 'person', 'tree', 'path', 'sun'],
'animals': ['dog'],
'people': true
}}
query = tokenizer.from_list_format([
{'image': 'https://images.rawpixel.com/image_800/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIzLTA4L3Jhd3BpeGVsX29mZmljZV8xNV9waG90b19vZl9hX2RvZ19ydW5uaW5nX3dpdGhfb3duZXJfYXRfcGFya19lcF9mM2I3MDQyZC0zNWJlLTRlMTQtOGZhNy1kY2Q2OWQ1YzQzZjlfMi5qcGc.jpg'}, # Either a local path or an url
{'text': "QUESTIONS/QUERIES GO HERE"},
])