backup
Browse files
app.py
CHANGED
@@ -41,54 +41,18 @@ model = PeftModel.from_pretrained(model, lora_weights_path)
|
|
41 |
model.tie_weights()
|
42 |
|
43 |
|
44 |
-
def
|
45 |
-
if not json_str:
|
46 |
-
print("DEBUG: Empty JSON string received")
|
47 |
-
return None
|
48 |
-
|
49 |
try:
|
50 |
-
#
|
51 |
-
|
52 |
-
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
json_str = json_str[1:-1]
|
58 |
-
|
59 |
-
# First parse - handles the outer JSON encoding
|
60 |
-
first_parse = json.loads(json_str)
|
61 |
-
print("DEBUG: First parse result type:", type(first_parse))
|
62 |
-
|
63 |
-
# Second parse - if the result is still a string, parse again
|
64 |
-
json_object = (
|
65 |
-
json.loads(first_parse) if isinstance(first_parse, str) else first_parse
|
66 |
-
)
|
67 |
-
print("DEBUG: Final parsed object type:", type(json_object))
|
68 |
-
|
69 |
-
# Validate expected keys
|
70 |
-
required_keys = [
|
71 |
-
"description",
|
72 |
-
"scene_description",
|
73 |
-
"character_list",
|
74 |
-
"object_list",
|
75 |
-
]
|
76 |
-
missing_keys = [key for key in required_keys if key not in json_object]
|
77 |
-
if missing_keys:
|
78 |
-
print("DEBUG: Missing required keys:", missing_keys)
|
79 |
-
return None
|
80 |
|
81 |
-
return json_object
|
82 |
except json.JSONDecodeError as e:
|
83 |
-
|
84 |
-
print(f"DEBUG: Error occurred at position {e.pos}")
|
85 |
-
print(
|
86 |
-
f"DEBUG: Problematic document snippet: {json_str[max(0, e.pos-50):e.pos+50]}"
|
87 |
-
)
|
88 |
-
return None
|
89 |
-
except Exception as e:
|
90 |
-
print(f"DEBUG: Unexpected error during JSON parsing: {e}")
|
91 |
-
return None
|
92 |
|
93 |
|
94 |
def create_color_palette_image(colors):
|
@@ -181,7 +145,7 @@ def inference(image):
|
|
181 |
"Error",
|
182 |
]
|
183 |
|
184 |
-
parsed_json =
|
185 |
if parsed_json:
|
186 |
# Create color palette visualization
|
187 |
colors = parsed_json.get("color_palette", [])
|
|
|
41 |
model.tie_weights()
|
42 |
|
43 |
|
44 |
+
def describe_image_in_JSON(json_string):
|
|
|
|
|
|
|
|
|
45 |
try:
|
46 |
+
# First JSON decode
|
47 |
+
first_decode = json.loads(json_string)
|
48 |
+
|
49 |
+
# Second JSON decode - parse the actual data
|
50 |
+
final_data = json.loads(first_decode)
|
51 |
+
|
52 |
+
return final_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
|
|
54 |
except json.JSONDecodeError as e:
|
55 |
+
return f"Error parsing JSON: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
|
58 |
def create_color_palette_image(colors):
|
|
|
145 |
"Error",
|
146 |
]
|
147 |
|
148 |
+
parsed_json = describe_image_in_JSON(json_str)
|
149 |
if parsed_json:
|
150 |
# Create color palette visualization
|
151 |
colors = parsed_json.get("color_palette", [])
|