wishmi1234 commited on
Commit
bdd5c0a
·
verified ·
1 Parent(s): 784eea6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
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 Dict
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": Dict, "question": "str"}
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
- # ignoring image context for now since agent.run doesn't support it
 
 
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