Fix: Improve input parsing and error handling for complex input structures
Browse files- handler.py +24 -7
handler.py
CHANGED
@@ -50,18 +50,34 @@ class EndpointHandler:
|
|
50 |
try:
|
51 |
# Parse inputs
|
52 |
if isinstance(inputs, str):
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
input_data = inputs.get("inputs", inputs)
|
59 |
if isinstance(input_data, str):
|
60 |
prompts = [input_data]
|
61 |
edit_type = "generate"
|
62 |
-
|
63 |
prompts = input_data.get("prompts", [input_data.get("prompt", "a simple sketch")])
|
64 |
edit_type = input_data.get("edit_type", "generate")
|
|
|
|
|
|
|
65 |
|
66 |
parameters = inputs.get("parameters", {})
|
67 |
|
@@ -724,8 +740,9 @@ class EndpointHandler:
|
|
724 |
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), fill='white'))
|
725 |
|
726 |
# Simple centered text
|
|
|
727 |
dwg.add(dwg.text(
|
728 |
-
f"DiffSketchEdit\n{
|
729 |
insert=(width/2, height/2),
|
730 |
text_anchor="middle",
|
731 |
font_size="12px",
|
|
|
50 |
try:
|
51 |
# Parse inputs
|
52 |
if isinstance(inputs, str):
|
53 |
+
# Check if it's a JSON string
|
54 |
+
try:
|
55 |
+
import json
|
56 |
+
parsed_inputs = json.loads(inputs)
|
57 |
+
if isinstance(parsed_inputs, dict):
|
58 |
+
inputs = parsed_inputs
|
59 |
+
else:
|
60 |
+
# Simple prompt - treat as generation
|
61 |
+
prompts = [inputs]
|
62 |
+
edit_type = "generate"
|
63 |
+
parameters = {}
|
64 |
+
except:
|
65 |
+
# Simple prompt - treat as generation
|
66 |
+
prompts = [inputs]
|
67 |
+
edit_type = "generate"
|
68 |
+
parameters = {}
|
69 |
+
|
70 |
+
if isinstance(inputs, dict):
|
71 |
input_data = inputs.get("inputs", inputs)
|
72 |
if isinstance(input_data, str):
|
73 |
prompts = [input_data]
|
74 |
edit_type = "generate"
|
75 |
+
elif isinstance(input_data, dict):
|
76 |
prompts = input_data.get("prompts", [input_data.get("prompt", "a simple sketch")])
|
77 |
edit_type = input_data.get("edit_type", "generate")
|
78 |
+
else:
|
79 |
+
prompts = ["a simple sketch"]
|
80 |
+
edit_type = "generate"
|
81 |
|
82 |
parameters = inputs.get("parameters", {})
|
83 |
|
|
|
740 |
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), fill='white'))
|
741 |
|
742 |
# Simple centered text
|
743 |
+
prompt_str = str(prompt)[:30] if prompt else "error"
|
744 |
dwg.add(dwg.text(
|
745 |
+
f"DiffSketchEdit\n{prompt_str}...",
|
746 |
insert=(width/2, height/2),
|
747 |
text_anchor="middle",
|
748 |
font_size="12px",
|