Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from PIL import Image
|
|
| 10 |
from io import BytesIO
|
| 11 |
import base64
|
| 12 |
from smolagents import load_tool
|
| 13 |
-
from typing import
|
| 14 |
|
| 15 |
model = InferenceClientModel("qwen/Qwen2.5-0.5B-Instruct",
|
| 16 |
max_tokens=512,
|
|
@@ -40,7 +40,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 40 |
class ImageCaptioningTool(Tool):
|
| 41 |
name = "image_captioner"
|
| 42 |
description = "Generate a caption for an image."
|
| 43 |
-
inputs = {"image":
|
| 44 |
output_type = "text"
|
| 45 |
|
| 46 |
def run(self, inputs: dict) -> str:
|
|
@@ -75,12 +75,7 @@ tools = [
|
|
| 75 |
# ---------------------- MAIN LOGIC ---------------------- #
|
| 76 |
|
| 77 |
class BasicAgent:
|
| 78 |
-
def __init__(self):
|
| 79 |
-
model = InferenceClientModel(
|
| 80 |
-
"qwen/Qwen2.5-0.5B-Instruct",
|
| 81 |
-
max_tokens=512
|
| 82 |
-
|
| 83 |
-
)
|
| 84 |
self.agent = CodeAgent(
|
| 85 |
tools = tools,
|
| 86 |
model=model
|
|
@@ -91,7 +86,9 @@ class BasicAgent:
|
|
| 91 |
def __call__(self, question):
|
| 92 |
if isinstance(question, dict):
|
| 93 |
text = question.get("question", "")
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
text = question
|
| 97 |
|
|
|
|
| 10 |
from io import BytesIO
|
| 11 |
import base64
|
| 12 |
from smolagents import load_tool
|
| 13 |
+
from typing import Any
|
| 14 |
|
| 15 |
model = InferenceClientModel("qwen/Qwen2.5-0.5B-Instruct",
|
| 16 |
max_tokens=512,
|
|
|
|
| 40 |
class ImageCaptioningTool(Tool):
|
| 41 |
name = "image_captioner"
|
| 42 |
description = "Generate a caption for an image."
|
| 43 |
+
inputs = {"image": Any, "question": "str"}
|
| 44 |
output_type = "text"
|
| 45 |
|
| 46 |
def run(self, inputs: dict) -> str:
|
|
|
|
| 75 |
# ---------------------- MAIN LOGIC ---------------------- #
|
| 76 |
|
| 77 |
class BasicAgent:
|
| 78 |
+
def __init__(self, model, tools):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
self.agent = CodeAgent(
|
| 80 |
tools = tools,
|
| 81 |
model=model
|
|
|
|
| 86 |
def __call__(self, question):
|
| 87 |
if isinstance(question, dict):
|
| 88 |
text = question.get("question", "")
|
| 89 |
+
image = question.get("image", None)
|
| 90 |
+
if image:
|
| 91 |
+
question["image"] = {"type": "pil", "data": image}
|
| 92 |
else:
|
| 93 |
text = question
|
| 94 |
|