Spaces:
Running
Running
refactor -- following guidelines to push tools
Browse files
tool.py
CHANGED
@@ -153,6 +153,8 @@ class VisualRAGTool(Tool):
|
|
153 |
}
|
154 |
output_type = "string"
|
155 |
|
|
|
|
|
156 |
def _init_models(self, model_name: str) -> None:
|
157 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
158 |
self.model = ColQwen2.from_pretrained(
|
@@ -163,27 +165,18 @@ class VisualRAGTool(Tool):
|
|
163 |
).eval()
|
164 |
self.processor = ColQwen2Processor.from_pretrained(model_name)
|
165 |
|
166 |
-
def __init__(self,
|
167 |
-
|
168 |
-
self.model_name = model_name
|
169 |
-
self.api_key = api_key
|
170 |
-
|
171 |
-
self.embds = []
|
172 |
-
self.pages = []
|
173 |
-
|
174 |
-
self.files = files
|
175 |
-
|
176 |
-
self._init_models(self.model_name)
|
177 |
-
|
178 |
-
self.is_initialized = False
|
179 |
|
180 |
def setup(self):
|
181 |
"""
|
182 |
Overwrite this method here for any operation that is expensive and needs to be executed before you start using
|
183 |
your tool. Such as loading a big model.
|
184 |
"""
|
185 |
-
|
186 |
-
|
|
|
|
|
187 |
|
188 |
self.is_initialized = True
|
189 |
|
@@ -195,7 +188,7 @@ class VisualRAGTool(Tool):
|
|
195 |
'query': "Give the general context about these pages. Give the context in the same language as the documents.",
|
196 |
'pages': [Page(image=im) for im in images[max(i-window+1, 0):i+1]],
|
197 |
'api_key': api_key,
|
198 |
-
'system_prompt':
|
199 |
} for i in range(0, len(images), window)
|
200 |
]
|
201 |
window_contexts = pqdm(args, query_openai, n_jobs=8, argument_type='kwargs')
|
|
|
153 |
}
|
154 |
output_type = "string"
|
155 |
|
156 |
+
model_name: str = "vidore/colqwen2-v1.0"
|
157 |
+
|
158 |
def _init_models(self, model_name: str) -> None:
|
159 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
160 |
self.model = ColQwen2.from_pretrained(
|
|
|
165 |
).eval()
|
166 |
self.processor = ColQwen2Processor.from_pretrained(model_name)
|
167 |
|
168 |
+
def __init__(self, *args, **kwargs):
|
169 |
+
self.is_initialized = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
def setup(self):
|
172 |
"""
|
173 |
Overwrite this method here for any operation that is expensive and needs to be executed before you start using
|
174 |
your tool. Such as loading a big model.
|
175 |
"""
|
176 |
+
self._init_models(self.model_name)
|
177 |
+
|
178 |
+
self.embds = []
|
179 |
+
self.pages = []
|
180 |
|
181 |
self.is_initialized = True
|
182 |
|
|
|
188 |
'query': "Give the general context about these pages. Give the context in the same language as the documents.",
|
189 |
'pages': [Page(image=im) for im in images[max(i-window+1, 0):i+1]],
|
190 |
'api_key': api_key,
|
191 |
+
'system_prompt': CONTEXT_SYSTEM_PROMPT,
|
192 |
} for i in range(0, len(images), window)
|
193 |
]
|
194 |
window_contexts = pqdm(args, query_openai, n_jobs=8, argument_type='kwargs')
|