SolshineMisfit commited on
Commit
39911e2
·
verified ·
1 Parent(s): e95248e

Change in HF upload URL display

Browse files
Files changed (1) hide show
  1. app.py +14 -11
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 representation of conversation to save (plain text)
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") # Use the provided username as default
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
- # Create a conversation object
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
- # First try to create the repository explicitly
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 to the Hugging Face Hub with explicit parameters
104
  dataset.push_to_hub(
105
  repo_id=repo_id,
106
  token=api_key,
107
- create_repo=True, # Create the repo if it doesn't exist
108
- repo_type="dataset", # Explicitly specify this is a dataset
109
  commit_message="Add conversation dataset"
110
  )
111
 
112
- return f"Successfully created dataset at https://huggingface.co/datasets/{repo_id}"
 
 
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
- dataset_creator_response = Dataset_Creator_Function(dataset_name, conversation_data)
129
- return dataset_creator_response
 
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