PolPC13 commited on
Commit
3b0eab7
·
1 Parent(s): 134ea6c

Removed query image tool.

Browse files
Files changed (1) hide show
  1. tools/new_tools.py +1 -67
tools/new_tools.py CHANGED
@@ -38,73 +38,7 @@ class WikiSearchTool(Tool):
38
  return f"wiki_search failed {e}"
39
 
40
 
41
- class QueryImageTool(Tool):
42
- name = "query_image"
43
- description = (
44
- "Analyze an image with a VLM given a natural language query and an image URL. "
45
- "Args: query (str), image_url (str). Returns: textual response."
46
- )
47
- inputs = {
48
- "query": {
49
- "type": "string",
50
- "description": "Question or instruction about the image."
51
- },
52
- "image_url": {
53
- "type": "string",
54
- "description": "Public URL of the image to analyze."
55
- },
56
- }
57
- output_type = "string"
58
-
59
- def forward(self, query: str, image_url: str) -> str:
60
- try:
61
- model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
62
- "Qwen/Qwen2.5-VL-3B-Instruct", torch_dtype="auto", device_map="auto"
63
- )
64
-
65
- processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")
66
-
67
- messages = [
68
- {
69
- "role": "user",
70
- "content": [
71
- {
72
- "type": "image",
73
- "image": image_url,
74
- "max_pixels": 360 * 420,
75
- },
76
- {"type": "text", "text": query},
77
- ],
78
- }
79
- ]
80
-
81
- text = processor.apply_chat_template(
82
- messages, tokenize=False, add_generation_prompt=True
83
- )
84
- image_inputs, video_inputs = process_vision_info(messages)
85
- inputs = processor(
86
- text=[text],
87
- images=image_inputs,
88
- videos=video_inputs,
89
- padding=True,
90
- return_tensors="pt",
91
- )
92
- inputs = inputs.to("cuda")
93
-
94
- generated_ids = model.generate(**inputs, max_new_tokens=128)
95
- generated_ids_trimmed = [
96
- out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
97
- ]
98
- output_text = processor.batch_decode(
99
- generated_ids_trimmed,
100
- skip_special_tokens=True,
101
- clean_up_tokenization_spaces=False,
102
- )
103
- # original function returned a list; keep or cast to str as you prefer
104
- return output_text[0] if isinstance(output_text, list) else output_text
105
- except Exception as e:
106
- return f"query_image failed {e}"
107
-
108
 
109
  class ReverseStringTool(Tool):
110
  name = "reverse_string"
 
38
  return f"wiki_search failed {e}"
39
 
40
 
41
+ c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  class ReverseStringTool(Tool):
44
  name = "reverse_string"