SolshineMisfit commited on
Commit
140d4bf
·
verified ·
1 Parent(s): 655eb16

Changed to use string instead of json inside the hugging face dataset upload function

Browse files
Files changed (1) hide show
  1. app.py +9 -16
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: JSON string or formatted text of conversation to save
60
 
61
  Returns:
62
  URL of the created dataset or error message
@@ -72,25 +72,18 @@ def Dataset_Creator_Function(dataset_name: str, conversation_data: str) -> str:
72
  # Format the full repo name
73
  repo_id = f"{username}/{dataset_name}"
74
 
75
- # If conversation_data is a string, try to parse it as JSON
76
- if isinstance(conversation_data, str):
77
- try:
78
- conversation = json.loads(conversation_data)
79
- except json.JSONDecodeError:
80
- # If not valid JSON, treat as raw text
81
- conversation = {"text": conversation_data}
82
- else:
83
- conversation = conversation_data
84
-
85
- # Add metadata
86
- conversation["timestamp"] = datetime.datetime.now().isoformat()
87
- conversation["dataset_id"] = str(uuid.uuid4())
88
 
89
  # Create a Hugging Face dataset
90
  dataset = Dataset.from_dict({"conversations": [conversation]})
91
 
92
  # Push to the Hugging Face Hub
93
- dataset.push_to_hub(repo_id, token=os.getenv("HF_API_KEY", ""))
94
 
95
  return f"Successfully created dataset at https://huggingface.co/datasets/{repo_id}"
96
  except Exception as e:
@@ -102,7 +95,7 @@ def Dataset_Creator_Tool(dataset_name: str, conversation_data: str) -> str:
102
 
103
  Args:
104
  dataset_name: Name for the dataset (will be prefixed with username)
105
- conversation_data: Conversation history as JSON string or formatted text
106
  """
107
  try:
108
  dataset_creator_response = Dataset_Creator_Function(dataset_name, conversation_data)
 
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
 
72
  # Format the full repo name
73
  repo_id = f"{username}/{dataset_name}"
74
 
75
+ # Create a conversation object
76
+ conversation = {
77
+ "text": conversation_data,
78
+ "timestamp": datetime.datetime.now().isoformat(),
79
+ "dataset_id": str(uuid.uuid4())
80
+ }
 
 
 
 
 
 
 
81
 
82
  # Create a Hugging Face dataset
83
  dataset = Dataset.from_dict({"conversations": [conversation]})
84
 
85
  # Push to the Hugging Face Hub
86
+ dataset.push_to_hub(repo_id, token=os.getenv("HUGGINGFACE_API_KEY", ""))
87
 
88
  return f"Successfully created dataset at https://huggingface.co/datasets/{repo_id}"
89
  except Exception as e:
 
95
 
96
  Args:
97
  dataset_name: Name for the dataset (will be prefixed with username)
98
+ conversation_data: String content to save to the dataset (no JSON conversion needed)
99
  """
100
  try:
101
  dataset_creator_response = Dataset_Creator_Function(dataset_name, conversation_data)