Spaces:
Running
on
Zero
Running
on
Zero
update app
Browse files
app.py
CHANGED
|
@@ -145,20 +145,27 @@ def run_model_inference(formatted_messages, max_tokens=1024, stop_sequences=None
|
|
| 145 |
|
| 146 |
|
| 147 |
class FaraLocalModel(Model):
|
|
|
|
|
|
|
|
|
|
| 148 |
def __init__(self, **kwargs):
|
| 149 |
super().__init__(**kwargs)
|
| 150 |
|
| 151 |
def __call__(
|
| 152 |
self,
|
| 153 |
-
messages: List[
|
| 154 |
stop_sequences: Optional[List[str]] = None,
|
|
|
|
| 155 |
**kwargs,
|
| 156 |
) -> ChatMessage:
|
| 157 |
|
| 158 |
formatted_messages = []
|
|
|
|
| 159 |
for msg in messages:
|
| 160 |
-
role
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
new_content = []
|
| 163 |
|
| 164 |
if isinstance(content, str):
|
|
@@ -170,6 +177,7 @@ class FaraLocalModel(Model):
|
|
| 170 |
elif isinstance(item, dict):
|
| 171 |
if "type" in item:
|
| 172 |
if item["type"] == "image":
|
|
|
|
| 173 |
val = item.get("image") or item.get("url") or item.get("path")
|
| 174 |
new_content.append({"type": "image", "image": val})
|
| 175 |
else:
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
class FaraLocalModel(Model):
|
| 148 |
+
"""
|
| 149 |
+
Wrapper for the local Fara (Qwen2.5-VL) model to work with SmolAgents.
|
| 150 |
+
"""
|
| 151 |
def __init__(self, **kwargs):
|
| 152 |
super().__init__(**kwargs)
|
| 153 |
|
| 154 |
def __call__(
|
| 155 |
self,
|
| 156 |
+
messages: List[ChatMessage],
|
| 157 |
stop_sequences: Optional[List[str]] = None,
|
| 158 |
+
grammar: Optional[str] = None,
|
| 159 |
**kwargs,
|
| 160 |
) -> ChatMessage:
|
| 161 |
|
| 162 |
formatted_messages = []
|
| 163 |
+
|
| 164 |
for msg in messages:
|
| 165 |
+
# Safely access role and content from ChatMessage object using attributes
|
| 166 |
+
role = msg.role if hasattr(msg, "role") else "user"
|
| 167 |
+
content = msg.content if hasattr(msg, "content") else ""
|
| 168 |
+
|
| 169 |
new_content = []
|
| 170 |
|
| 171 |
if isinstance(content, str):
|
|
|
|
| 177 |
elif isinstance(item, dict):
|
| 178 |
if "type" in item:
|
| 179 |
if item["type"] == "image":
|
| 180 |
+
# Handle path or url - extract value to ensure serializability
|
| 181 |
val = item.get("image") or item.get("url") or item.get("path")
|
| 182 |
new_content.append({"type": "image", "image": val})
|
| 183 |
else:
|