Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,23 @@ async def process_constraints(constraints: InputConstraints):
|
|
| 43 |
result = process_input_from_constraints(constraints.constraints, global_tech, global_tech_embeddings)
|
| 44 |
return {"technologies": result}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def process_input_gradio(problem_description: str):
|
| 47 |
"""
|
| 48 |
Processes the input problem description step-by-step for Gradio.
|
|
@@ -86,8 +103,14 @@ def process_input_gradio(problem_description: str):
|
|
| 86 |
for item in result_similarities
|
| 87 |
}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
return (
|
| 93 |
prompt,
|
|
|
|
| 43 |
result = process_input_from_constraints(constraints.constraints, global_tech, global_tech_embeddings)
|
| 44 |
return {"technologies": result}
|
| 45 |
|
| 46 |
+
|
| 47 |
+
def make_json_serializable(data):
|
| 48 |
+
"""
|
| 49 |
+
Recursively convert tensors to floats in a data structure
|
| 50 |
+
so it can be passed to json.dumps.
|
| 51 |
+
"""
|
| 52 |
+
if isinstance(data, dict):
|
| 53 |
+
return {k: make_json_serializable(v) for k, v in data.items()}
|
| 54 |
+
elif isinstance(data, list):
|
| 55 |
+
return [make_json_serializable(item) for item in data]
|
| 56 |
+
elif isinstance(data, tuple):
|
| 57 |
+
return tuple(make_json_serializable(item) for item in data)
|
| 58 |
+
elif hasattr(data, 'item'): # torch.Tensor with single value
|
| 59 |
+
return float(data.item())
|
| 60 |
+
else:
|
| 61 |
+
return data
|
| 62 |
+
|
| 63 |
def process_input_gradio(problem_description: str):
|
| 64 |
"""
|
| 65 |
Processes the input problem description step-by-step for Gradio.
|
|
|
|
| 103 |
for item in result_similarities
|
| 104 |
}
|
| 105 |
|
| 106 |
+
|
| 107 |
+
# Convert to JSON-safe format
|
| 108 |
+
safe_best_combinations = make_json_serializable(best_combinations)
|
| 109 |
+
safe_best_technologies = make_json_serializable(best_technologies)
|
| 110 |
+
|
| 111 |
+
# Now this will work safely:
|
| 112 |
+
best_combinations_display = json.dumps(safe_best_combinations, indent=2)
|
| 113 |
+
best_technologies_display = json.dumps(safe_best_technologies, indent=2)
|
| 114 |
|
| 115 |
return (
|
| 116 |
prompt,
|