Spaces:
Runtime error
Runtime error
Change in HF upload URL display
Browse files
app.py
CHANGED
|
@@ -56,7 +56,7 @@ def Dataset_Creator_Function(dataset_name: str, conversation_data: str) -> str:
|
|
| 56 |
|
| 57 |
Args:
|
| 58 |
dataset_name: Name for the dataset (will be prefixed with username)
|
| 59 |
-
conversation_data: String
|
| 60 |
|
| 61 |
Returns:
|
| 62 |
URL of the created dataset or error message
|
|
@@ -73,7 +73,7 @@ def Dataset_Creator_Function(dataset_name: str, conversation_data: str) -> str:
|
|
| 73 |
# Get username for the repository name
|
| 74 |
try:
|
| 75 |
user_info = hf_api.whoami()
|
| 76 |
-
username = user_info.get("name", "Misfits-and-Machines") #
|
| 77 |
except Exception as e:
|
| 78 |
return f"Error authenticating with Hugging Face: {str(e)}"
|
| 79 |
|
|
@@ -83,7 +83,7 @@ def Dataset_Creator_Function(dataset_name: str, conversation_data: str) -> str:
|
|
| 83 |
|
| 84 |
print(f"Creating dataset repository: {repo_id}")
|
| 85 |
|
| 86 |
-
#
|
| 87 |
conversation = {
|
| 88 |
"text": conversation_data,
|
| 89 |
"timestamp": datetime.datetime.now().isoformat(),
|
|
@@ -93,23 +93,25 @@ def Dataset_Creator_Function(dataset_name: str, conversation_data: str) -> str:
|
|
| 93 |
# Create a Hugging Face dataset
|
| 94 |
dataset = Dataset.from_dict({"conversations": [conversation]})
|
| 95 |
|
| 96 |
-
#
|
| 97 |
try:
|
| 98 |
hf_api.create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True)
|
| 99 |
print(f"Repository {repo_id} created or already exists")
|
| 100 |
except Exception as repo_error:
|
| 101 |
print(f"Note: Repository creation returned: {str(repo_error)}")
|
| 102 |
|
| 103 |
-
# Push
|
| 104 |
dataset.push_to_hub(
|
| 105 |
repo_id=repo_id,
|
| 106 |
token=api_key,
|
| 107 |
-
create_repo=True,
|
| 108 |
-
repo_type="dataset",
|
| 109 |
commit_message="Add conversation dataset"
|
| 110 |
)
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
import traceback
|
| 115 |
error_trace = traceback.format_exc()
|
|
@@ -123,10 +125,11 @@ def Dataset_Creator_Tool(dataset_name: str, conversation_data: str) -> str:
|
|
| 123 |
Args:
|
| 124 |
dataset_name: Name for the dataset (will be prefixed with username)
|
| 125 |
conversation_data: String content to save to the dataset (no JSON conversion needed)
|
| 126 |
-
|
| 127 |
try:
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
except Exception as e:
|
| 131 |
return f"Error using Dataset Creator tool: {str(e)}"
|
| 132 |
|
|
|
|
| 56 |
|
| 57 |
Args:
|
| 58 |
dataset_name: Name for the dataset (will be prefixed with username)
|
| 59 |
+
conversation_data: String representing the conversation data
|
| 60 |
|
| 61 |
Returns:
|
| 62 |
URL of the created dataset or error message
|
|
|
|
| 73 |
# Get username for the repository name
|
| 74 |
try:
|
| 75 |
user_info = hf_api.whoami()
|
| 76 |
+
username = user_info.get("name", "Misfits-and-Machines") # fallback
|
| 77 |
except Exception as e:
|
| 78 |
return f"Error authenticating with Hugging Face: {str(e)}"
|
| 79 |
|
|
|
|
| 83 |
|
| 84 |
print(f"Creating dataset repository: {repo_id}")
|
| 85 |
|
| 86 |
+
# Build conversation object
|
| 87 |
conversation = {
|
| 88 |
"text": conversation_data,
|
| 89 |
"timestamp": datetime.datetime.now().isoformat(),
|
|
|
|
| 93 |
# Create a Hugging Face dataset
|
| 94 |
dataset = Dataset.from_dict({"conversations": [conversation]})
|
| 95 |
|
| 96 |
+
# Create or confirm the repo exists
|
| 97 |
try:
|
| 98 |
hf_api.create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True)
|
| 99 |
print(f"Repository {repo_id} created or already exists")
|
| 100 |
except Exception as repo_error:
|
| 101 |
print(f"Note: Repository creation returned: {str(repo_error)}")
|
| 102 |
|
| 103 |
+
# Push the dataset
|
| 104 |
dataset.push_to_hub(
|
| 105 |
repo_id=repo_id,
|
| 106 |
token=api_key,
|
| 107 |
+
create_repo=True,
|
| 108 |
+
repo_type="dataset",
|
| 109 |
commit_message="Add conversation dataset"
|
| 110 |
)
|
| 111 |
|
| 112 |
+
dataset_url = f"https://huggingface.co/datasets/{repo_id}"
|
| 113 |
+
print(f"Dataset successfully pushed to {dataset_url}")
|
| 114 |
+
return dataset_url
|
| 115 |
except Exception as e:
|
| 116 |
import traceback
|
| 117 |
error_trace = traceback.format_exc()
|
|
|
|
| 125 |
Args:
|
| 126 |
dataset_name: Name for the dataset (will be prefixed with username)
|
| 127 |
conversation_data: String content to save to the dataset (no JSON conversion needed)
|
| 128 |
+
"""
|
| 129 |
try:
|
| 130 |
+
result = Dataset_Creator_Function(dataset_name, conversation_data)
|
| 131 |
+
print(f"Dataset_Creator_Function returned: {result}")
|
| 132 |
+
return result
|
| 133 |
except Exception as e:
|
| 134 |
return f"Error using Dataset Creator tool: {str(e)}"
|
| 135 |
|