Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,6 +51,23 @@ def submit_query(session_id, query):
|
|
51 |
response = requests.post(submit_query_url, headers=submit_query_headers, json=submit_query_body)
|
52 |
return response.json()
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
def load_model():
|
55 |
try:
|
56 |
model_path = 'model_epoch_01.h5.keras'
|
|
|
51 |
response = requests.post(submit_query_url, headers=submit_query_headers, json=submit_query_body)
|
52 |
return response.json()
|
53 |
|
54 |
+
def extract_json_from_answer(answer):
|
55 |
+
"""Extract and clean JSON from the LLM response"""
|
56 |
+
try:
|
57 |
+
# First try to parse the answer directly
|
58 |
+
return json.loads(answer)
|
59 |
+
except json.JSONDecodeError:
|
60 |
+
try:
|
61 |
+
# If that fails, try to find JSON content and parse it
|
62 |
+
start_idx = answer.find('{')
|
63 |
+
end_idx = answer.rfind('}') + 1
|
64 |
+
if start_idx != -1 and end_idx != 0:
|
65 |
+
json_str = answer[start_idx:end_idx]
|
66 |
+
return json.loads(json_str)
|
67 |
+
except (json.JSONDecodeError, ValueError):
|
68 |
+
logger.error("Failed to parse JSON from response")
|
69 |
+
raise
|
70 |
+
|
71 |
def load_model():
|
72 |
try:
|
73 |
model_path = 'model_epoch_01.h5.keras'
|