meirk-brd commited on
Commit
0cc79aa
·
1 Parent(s): 0a73403

require url

Browse files
Files changed (1) hide show
  1. tool.py +22 -8
tool.py CHANGED
@@ -223,6 +223,12 @@ class BrightDataDatasetTool(Tool):
223
  return self._ensure_scheme(raw)
224
 
225
  if isinstance(raw, dict):
 
 
 
 
 
 
226
  orig_name = raw.get("orig_name")
227
  if (
228
  isinstance(orig_name, str)
@@ -237,14 +243,9 @@ class BrightDataDatasetTool(Tool):
237
  return url_value
238
  if url_value.startswith("/gradio_api/file="):
239
  file_path = url_value.split("=", 1)[-1]
240
- if os.path.isfile(file_path):
241
- try:
242
- with open(file_path, "r", encoding="utf-8", errors="ignore") as fh:
243
- text = fh.read().strip()
244
- if text and not text.lstrip().startswith("<"):
245
- return self._ensure_scheme(text)
246
- except OSError:
247
- pass
248
  return None
249
 
250
  return None
@@ -261,6 +262,19 @@ class BrightDataDatasetTool(Tool):
261
  except (ValueError, SyntaxError):
262
  return None
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  def _get_gradio_app_code(self, tool_module_name: str = "tool") -> str:
265
  choices = sorted(self.datasets.keys())
266
  dataset_fields = {key: value["inputs"] for key, value in self.datasets.items()}
 
223
  return self._ensure_scheme(raw)
224
 
225
  if isinstance(raw, dict):
226
+ file_path = raw.get("path")
227
+ if isinstance(file_path, str) and os.path.isfile(file_path):
228
+ text = self._read_text_file(file_path)
229
+ if text:
230
+ return self._ensure_scheme(text)
231
+
232
  orig_name = raw.get("orig_name")
233
  if (
234
  isinstance(orig_name, str)
 
243
  return url_value
244
  if url_value.startswith("/gradio_api/file="):
245
  file_path = url_value.split("=", 1)[-1]
246
+ text = self._read_text_file(file_path)
247
+ if text:
248
+ return self._ensure_scheme(text)
 
 
 
 
 
249
  return None
250
 
251
  return None
 
262
  except (ValueError, SyntaxError):
263
  return None
264
 
265
+ def _read_text_file(self, path: str) -> Optional[str]:
266
+ if not os.path.isfile(path):
267
+ return None
268
+ try:
269
+ with open(path, "r", encoding="utf-8", errors="ignore") as fh:
270
+ for line in fh:
271
+ text = line.strip()
272
+ if text and not text.startswith("<"):
273
+ return text
274
+ except OSError:
275
+ return None
276
+ return None
277
+
278
  def _get_gradio_app_code(self, tool_module_name: str = "tool") -> str:
279
  choices = sorted(self.datasets.keys())
280
  dataset_fields = {key: value["inputs"] for key, value in self.datasets.items()}