Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -117,9 +117,8 @@ def preprocess_text(text):
|
|
117 |
return text.strip()
|
118 |
|
119 |
def sanitize_json_text(text):
|
120 |
-
|
121 |
-
text =
|
122 |
-
text = json.dumps(text)[1:-1] # Wrap in quotes and remove them to escape properly
|
123 |
return text
|
124 |
|
125 |
def extract_pdf_text(pdf_file):
|
@@ -165,7 +164,7 @@ def delete_record(container, record):
|
|
165 |
try:
|
166 |
doc_id = record["id"]
|
167 |
partition_key_value = record.get("pk", doc_id)
|
168 |
-
st.write(f"
|
169 |
container.delete_item(item=doc_id, partition_key=partition_key_value)
|
170 |
return True, f"Record {doc_id} deleted. 🗑️"
|
171 |
except exceptions.CosmosResourceNotFoundError:
|
@@ -394,15 +393,12 @@ def edit_all_documents(container, search_keyword=None):
|
|
394 |
with col_save:
|
395 |
if st.button("💾 Save", key=f"save_{doc['id']}"):
|
396 |
try:
|
397 |
-
# Handle raw text pasted into editor
|
398 |
cleaned_content = edited_content.strip()
|
399 |
if not (cleaned_content.startswith('{') and cleaned_content.endswith('}')):
|
400 |
-
# If not JSON, assume raw text and wrap it
|
401 |
sanitized_text = sanitize_json_text(cleaned_content)
|
402 |
updated_doc = doc.copy()
|
403 |
updated_doc['content'] = sanitized_text
|
404 |
else:
|
405 |
-
# If JSON, parse it directly
|
406 |
updated_doc = json.loads(cleaned_content)
|
407 |
updated_doc['id'] = doc['id']
|
408 |
updated_doc['pk'] = doc.get('pk', doc['id'])
|
|
|
117 |
return text.strip()
|
118 |
|
119 |
def sanitize_json_text(text):
|
120 |
+
text = text.encode().decode('unicode_escape')
|
121 |
+
text = json.dumps(text)[1:-1]
|
|
|
122 |
return text
|
123 |
|
124 |
def extract_pdf_text(pdf_file):
|
|
|
164 |
try:
|
165 |
doc_id = record["id"]
|
166 |
partition_key_value = record.get("pk", doc_id)
|
167 |
+
st.write(f"Deleting {doc_id} with partition key {partition_key_value}")
|
168 |
container.delete_item(item=doc_id, partition_key=partition_key_value)
|
169 |
return True, f"Record {doc_id} deleted. 🗑️"
|
170 |
except exceptions.CosmosResourceNotFoundError:
|
|
|
393 |
with col_save:
|
394 |
if st.button("💾 Save", key=f"save_{doc['id']}"):
|
395 |
try:
|
|
|
396 |
cleaned_content = edited_content.strip()
|
397 |
if not (cleaned_content.startswith('{') and cleaned_content.endswith('}')):
|
|
|
398 |
sanitized_text = sanitize_json_text(cleaned_content)
|
399 |
updated_doc = doc.copy()
|
400 |
updated_doc['content'] = sanitized_text
|
401 |
else:
|
|
|
402 |
updated_doc = json.loads(cleaned_content)
|
403 |
updated_doc['id'] = doc['id']
|
404 |
updated_doc['pk'] = doc.get('pk', doc['id'])
|