BenjaminKaindu0506 commited on
Commit
532c5d2
·
verified ·
1 Parent(s): a7ec422

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -35
app.py CHANGED
@@ -110,28 +110,28 @@ class BasicAgent:
110
  }
111
  output_type = "string"
112
 
113
- def forward(self, file_path: str, question: str) -> str:
114
- import base64
115
- from huggingface_hub import InferenceClient
116
-
117
- client = InferenceClient(token=os.environ["HF_TOKEN"])
118
- with open(file_path, "rb") as f:
119
- image_bytes = f.read()
120
- image_b64 = base64.b64encode(image_bytes).decode("utf-8")
121
-
122
- result = client.chat_completion(
123
- model="Qwen/Qwen2.5-VL-72B-Instruct",
124
- messages=[
125
- {
126
- "role": "user",
127
- "content": [
128
- {"type": "text", "text": question},
129
- {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}},
130
- ],
131
- }
132
- ],
133
- )
134
- return result.choices[0].message.content
135
 
136
 
137
  class TranscribeAudioTool(Tool):
@@ -145,18 +145,17 @@ class BasicAgent:
145
  }
146
  output_type = "string"
147
 
148
- def forward(self, file_path: str) -> str:
149
- from huggingface_hub import InferenceClient
150
- client = InferenceClient(token=os.environ["HF_TOKEN"])
151
- result = client.automatic_speech_recognition(
152
- file_path,
153
- model="openai/whisper-large-v3",
154
- )
155
- return result.text
156
- #pdf_tool = load_tool(
157
- #"matterattetatte/pdf-upload-extractor-tool",
158
- # trust_remote_code = True
159
- #)
160
  #read_pdf = ReadPDFTool()
161
  self.agent = CodeAgent(
162
  tools=[
@@ -174,7 +173,7 @@ class BasicAgent:
174
  ],
175
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct") ,
176
  additional_authorized_imports=["pandas", "requests", "re"],
177
- instructions = ("You are an advanced CodeAgent that will show your capabilities to work in the real world by being tested in GAIA, the agent testing platform. If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to pdf_tool, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix."
178
  "Use the Thought Action observation to produce high quality results and only answer when you are sure you have performed the necessary steps for the task and question"
179
  "If the file is an image, use analyze_image with a specific question about it"
180
  "what to find. If the file is audio, use transcribe_audio first, then reason over the transcribed text "
 
110
  }
111
  output_type = "string"
112
 
113
+ def forward(self, file_path: str, question: str) -> str:
114
+ import base64
115
+ from huggingface_hub import InferenceClient
116
+
117
+ client = InferenceClient(token=os.environ["HF_TOKEN"])
118
+ with open(file_path, "rb") as f:
119
+ image_bytes = f.read()
120
+ image_b64 = base64.b64encode(image_bytes).decode("utf-8")
121
+
122
+ result = client.chat_completion(
123
+ model="Qwen/Qwen2.5-VL-72B-Instruct",
124
+ messages=[
125
+ {
126
+ "role": "user",
127
+ "content": [
128
+ {"type": "text", "text": question},
129
+ {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}},
130
+ ],
131
+ }
132
+ ],
133
+ )
134
+ return result.choices[0].message.content
135
 
136
 
137
  class TranscribeAudioTool(Tool):
 
145
  }
146
  output_type = "string"
147
 
148
+ def forward(self, file_path: str) -> str:
149
+ from huggingface_hub import InferenceClient
150
+ client = InferenceClient(token=os.environ["HF_TOKEN"])
151
+ result = client.automatic_speech_recognition(
152
+ file_path,
153
+ model="openai/whisper-large-v3",
154
+ )
155
+ return result.text
156
+ read_pdf = ReadPDFTool()
157
+ analyze_image = AnalyzeImageTool()
158
+ transcribe_audio = TranscribeAudioTool()
 
159
  #read_pdf = ReadPDFTool()
160
  self.agent = CodeAgent(
161
  tools=[
 
173
  ],
174
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct") ,
175
  additional_authorized_imports=["pandas", "requests", "re"],
176
+ instructions = ("You are an advanced CodeAgent that will show your capabilities to work in the real world by being tested in GAIA, the agent testing platform. If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to read_pdf, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix."
177
  "Use the Thought Action observation to produce high quality results and only answer when you are sure you have performed the necessary steps for the task and question"
178
  "If the file is an image, use analyze_image with a specific question about it"
179
  "what to find. If the file is audio, use transcribe_audio first, then reason over the transcribed text "