Spaces:
Running
Running
Refactor conversation deletion logic: Update file retrieval method and enhance error handling for dataset access.
Browse files
app.py
CHANGED
|
@@ -814,9 +814,6 @@ def delete_conversation_from_huggingface(conversation_id):
|
|
| 814 |
Success status (bool) and message (str)
|
| 815 |
"""
|
| 816 |
try:
|
| 817 |
-
from huggingface_hub import HfApi, hf_hub_download
|
| 818 |
-
from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
|
| 819 |
-
|
| 820 |
if not conversation_id:
|
| 821 |
return False, "No conversation ID provided"
|
| 822 |
|
|
@@ -826,16 +823,16 @@ def delete_conversation_from_huggingface(conversation_id):
|
|
| 826 |
# Get list of files in dataset
|
| 827 |
try:
|
| 828 |
# Get all files in dataset
|
| 829 |
-
|
| 830 |
repo_id=DATASET_ID,
|
| 831 |
repo_type="dataset"
|
| 832 |
)
|
| 833 |
|
| 834 |
# Find files with matching conversation ID in chat history
|
| 835 |
chat_files = [
|
| 836 |
-
file for file in
|
| 837 |
-
if file.startswith(f"{DATASET_CHAT_HISTORY_PATH}/") and
|
| 838 |
-
f"{conversation_id}_" in os.path.basename(file)
|
| 839 |
]
|
| 840 |
|
| 841 |
if not chat_files:
|
|
@@ -868,8 +865,8 @@ def delete_conversation_from_huggingface(conversation_id):
|
|
| 868 |
|
| 869 |
return True, f"Deleted {len(chat_files)} file(s) from dataset for conversation: {conversation_id}"
|
| 870 |
|
| 871 |
-
except
|
| 872 |
-
return False, f"Dataset
|
| 873 |
|
| 874 |
except Exception as e:
|
| 875 |
logger.error(f"Error deleting conversation from dataset: {str(e)}")
|
|
|
|
| 814 |
Success status (bool) and message (str)
|
| 815 |
"""
|
| 816 |
try:
|
|
|
|
|
|
|
|
|
|
| 817 |
if not conversation_id:
|
| 818 |
return False, "No conversation ID provided"
|
| 819 |
|
|
|
|
| 823 |
# Get list of files in dataset
|
| 824 |
try:
|
| 825 |
# Get all files in dataset
|
| 826 |
+
files = api.list_files_info(
|
| 827 |
repo_id=DATASET_ID,
|
| 828 |
repo_type="dataset"
|
| 829 |
)
|
| 830 |
|
| 831 |
# Find files with matching conversation ID in chat history
|
| 832 |
chat_files = [
|
| 833 |
+
file.rfilename for file in files
|
| 834 |
+
if file.rfilename.startswith(f"{DATASET_CHAT_HISTORY_PATH}/") and
|
| 835 |
+
f"{conversation_id}_" in os.path.basename(file.rfilename)
|
| 836 |
]
|
| 837 |
|
| 838 |
if not chat_files:
|
|
|
|
| 865 |
|
| 866 |
return True, f"Deleted {len(chat_files)} file(s) from dataset for conversation: {conversation_id}"
|
| 867 |
|
| 868 |
+
except Exception as e:
|
| 869 |
+
return False, f"Dataset access error: {str(e)}"
|
| 870 |
|
| 871 |
except Exception as e:
|
| 872 |
logger.error(f"Error deleting conversation from dataset: {str(e)}")
|