Commit
·
e346232
1
Parent(s):
e43f4cc
Improve file path extraction for Gradio compatibility
Browse filesEnhanced file path extraction logic in both gradio_demo.py and openhands_poc/executor.py to support multiple Gradio versions (3.x and 4.x), handling both string paths and file-like objects. Added debug logging to aid in troubleshooting file object types and values.
- gradio_demo.py +14 -4
- openhands_poc/executor.py +16 -3
gradio_demo.py
CHANGED
|
@@ -484,15 +484,25 @@ async def handle_user_openhands(schedule_file: gr.File, drawing_file: gr.File, s
|
|
| 484 |
executor = get_executor()
|
| 485 |
loop = asyncio.get_event_loop()
|
| 486 |
|
| 487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
|
| 489 |
# Wrap in lambda to ensure proper argument binding (SDK pattern)
|
| 490 |
comparison_table, metadata = await loop.run_in_executor(
|
| 491 |
None,
|
| 492 |
lambda: executor.classify_and_compare_with_sdk(
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
)
|
| 497 |
)
|
| 498 |
print(f"=== Executor returned ===")
|
|
|
|
| 484 |
executor = get_executor()
|
| 485 |
loop = asyncio.get_event_loop()
|
| 486 |
|
| 487 |
+
# Debug: Log file object details
|
| 488 |
+
print(f"=== schedule_file type: {type(schedule_file)}, value: {schedule_file} ===")
|
| 489 |
+
print(f"=== drawing_file type: {type(drawing_file)}, value: {drawing_file} ===")
|
| 490 |
+
print(f"=== spec_file type: {type(spec_file)}, value: {spec_file} ===")
|
| 491 |
+
|
| 492 |
+
# Extract paths - handle both string paths (Gradio 4.x+) and file objects (Gradio 3.x)
|
| 493 |
+
schedule_path = schedule_file if isinstance(schedule_file, str) else schedule_file.name
|
| 494 |
+
drawing_path = drawing_file if isinstance(drawing_file, str) else drawing_file.name
|
| 495 |
+
spec_path = spec_file if isinstance(spec_file, str) else spec_file.name
|
| 496 |
+
|
| 497 |
+
print(f"=== Calling executor with files: {schedule_path}, {drawing_path}, {spec_path} ===")
|
| 498 |
|
| 499 |
# Wrap in lambda to ensure proper argument binding (SDK pattern)
|
| 500 |
comparison_table, metadata = await loop.run_in_executor(
|
| 501 |
None,
|
| 502 |
lambda: executor.classify_and_compare_with_sdk(
|
| 503 |
+
schedule_path,
|
| 504 |
+
drawing_path,
|
| 505 |
+
spec_path,
|
| 506 |
)
|
| 507 |
)
|
| 508 |
print(f"=== Executor returned ===")
|
openhands_poc/executor.py
CHANGED
|
@@ -307,14 +307,27 @@ class AgentExecutor:
|
|
| 307 |
Returns:
|
| 308 |
str: File path
|
| 309 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
if isinstance(file_obj, str):
|
| 311 |
return file_obj
|
| 312 |
-
|
|
|
|
| 313 |
return file_obj.name
|
| 314 |
-
|
|
|
|
| 315 |
return file_obj.path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
else:
|
| 317 |
-
raise ValueError(f"Cannot extract path from {type(file_obj)}")
|
| 318 |
|
| 319 |
|
| 320 |
# Global executor instance
|
|
|
|
| 307 |
Returns:
|
| 308 |
str: File path
|
| 309 |
"""
|
| 310 |
+
# Debug: Log what we received
|
| 311 |
+
print(f"[_get_file_path] Received type: {type(file_obj)}, value: {file_obj}")
|
| 312 |
+
if hasattr(file_obj, "__dict__"):
|
| 313 |
+
print(f"[_get_file_path] Object attrs: {file_obj.__dict__}")
|
| 314 |
+
|
| 315 |
+
# Gradio 4.x+ returns file path as string directly
|
| 316 |
if isinstance(file_obj, str):
|
| 317 |
return file_obj
|
| 318 |
+
# Gradio 3.x returns object with .name attribute (temp file path)
|
| 319 |
+
elif hasattr(file_obj, "name") and isinstance(file_obj.name, str) and len(file_obj.name) > 4:
|
| 320 |
return file_obj.name
|
| 321 |
+
# Some versions use .path
|
| 322 |
+
elif hasattr(file_obj, "path") and isinstance(file_obj.path, str):
|
| 323 |
return file_obj.path
|
| 324 |
+
# Handle NamedString or similar wrapper types
|
| 325 |
+
elif hasattr(file_obj, "orig_name"):
|
| 326 |
+
# Try to find the actual path
|
| 327 |
+
if hasattr(file_obj, "name"):
|
| 328 |
+
return str(file_obj.name)
|
| 329 |
else:
|
| 330 |
+
raise ValueError(f"Cannot extract path from {type(file_obj)}: {file_obj}")
|
| 331 |
|
| 332 |
|
| 333 |
# Global executor instance
|