meirk-brd commited on
Commit
7ee2792
·
1 Parent(s): 92b8ebf

read temp file

Browse files
Files changed (1) hide show
  1. tool.py +25 -3
tool.py CHANGED
@@ -106,7 +106,7 @@ class BrightDataDatasetTool(Tool):
106
  return json.dumps(data, indent=2)
107
  except requests.exceptions.RequestException as exc:
108
  details = exc.response.text if getattr(exc, "response", None) is not None else ""
109
- return json.dumps({"error": str(exc), "details": details, "payload": payload})
110
 
111
  def _build_params(
112
  self,
@@ -216,6 +216,16 @@ class BrightDataDatasetTool(Tool):
216
  return self._ensure_scheme(raw)
217
 
218
  if isinstance(raw, dict):
 
 
 
 
 
 
 
 
 
 
219
  orig_name = raw.get("orig_name")
220
  if (
221
  isinstance(orig_name, str)
@@ -225,8 +235,20 @@ class BrightDataDatasetTool(Tool):
225
  return self._ensure_scheme(orig_name)
226
 
227
  url_value = raw.get("url")
228
- if isinstance(url_value, str) and url_value.startswith(("http://", "https://")):
229
- return url_value
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
  return None
232
 
 
106
  return json.dumps(data, indent=2)
107
  except requests.exceptions.RequestException as exc:
108
  details = exc.response.text if getattr(exc, "response", None) is not None else ""
109
+ return json.dumps({"error": str(exc), "details": details, "payload": payload, "coerced_url": url})
110
 
111
  def _build_params(
112
  self,
 
216
  return self._ensure_scheme(raw)
217
 
218
  if isinstance(raw, dict):
219
+ path_value = raw.get("path")
220
+ if isinstance(path_value, str) and os.path.isfile(path_value):
221
+ try:
222
+ with open(path_value, "r", encoding="utf-8", errors="ignore") as fh:
223
+ text = fh.read().strip()
224
+ if text:
225
+ return self._ensure_scheme(text)
226
+ except OSError:
227
+ pass
228
+
229
  orig_name = raw.get("orig_name")
230
  if (
231
  isinstance(orig_name, str)
 
235
  return self._ensure_scheme(orig_name)
236
 
237
  url_value = raw.get("url")
238
+ if isinstance(url_value, str):
239
+ if url_value.startswith("/gradio_api/file="):
240
+ file_path = url_value.split("=", 1)[-1]
241
+ if os.path.isfile(file_path):
242
+ try:
243
+ with open(file_path, "r", encoding="utf-8", errors="ignore") as fh:
244
+ text = fh.read().strip()
245
+ if text:
246
+ return self._ensure_scheme(text)
247
+ except OSError:
248
+ pass
249
+ return None
250
+ if url_value.startswith(("http://", "https://")):
251
+ return url_value
252
 
253
  return None
254