Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -198,6 +198,30 @@ class HuggingFaceDocumentQATool:
|
|
198 |
except Exception as e:
|
199 |
return f"QA error: {str(e)}"
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
# ===== Code Execution =====
|
202 |
class PythonCodeExecutionTool:
|
203 |
def __init__(self):
|
|
|
198 |
except Exception as e:
|
199 |
return f"QA error: {str(e)}"
|
200 |
|
201 |
+
|
202 |
+
|
203 |
+
from transformers import BlipProcessor, BlipForQuestionAnswering
|
204 |
+
|
205 |
+
class HuggingFaceImageQATool(Tool):
|
206 |
+
name = "image_qa"
|
207 |
+
description = "Answer questions about an image."
|
208 |
+
inputs = {
|
209 |
+
"image_path": {"type": "string", "description": "Path to image"},
|
210 |
+
"question": {"type": "string", "description": "Question about the image"}
|
211 |
+
}
|
212 |
+
output_type = "string"
|
213 |
+
|
214 |
+
def __init__(self):
|
215 |
+
self.processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
216 |
+
self.model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
217 |
+
|
218 |
+
def forward(self, image_path: str, question: str) -> str:
|
219 |
+
image = Image.open(image_path)
|
220 |
+
inputs = self.processor(image, question, return_tensors="pt")
|
221 |
+
out = self.model.generate(**inputs)
|
222 |
+
return self.processor.decode(out[0], skip_special_tokens=True)
|
223 |
+
|
224 |
+
|
225 |
# ===== Code Execution =====
|
226 |
class PythonCodeExecutionTool:
|
227 |
def __init__(self):
|