kacapower commited on
Commit
b02d0dd
·
verified ·
1 Parent(s): 44c67f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -16,20 +16,18 @@ DATASET_REPO = "kacapower/lexical-space-data"
16
  THEME_FILE_NAME = "website_theme.xml"
17
 
18
  def save_theme_to_dataset(xml_file):
19
- """Saves the uploaded XML file to the private hf dataset."""
20
  if xml_file is None:
21
  return "❌ Please upload an XML file first."
22
 
23
- local_file = "temp_theme.xml"
24
-
25
  try:
26
- # Copy the uploaded file to a local path
27
- shutil.copyfile(xml_file.name, local_file)
28
 
29
- # 1. Upload using the bulletproof HfApi method
30
  api = HfApi()
31
  api.upload_file(
32
- path_or_fileobj=local_file,
33
  path_in_repo=THEME_FILE_NAME,
34
  repo_id=DATASET_REPO,
35
  repo_type="dataset",
 
16
  THEME_FILE_NAME = "website_theme.xml"
17
 
18
  def save_theme_to_dataset(xml_file):
19
+ """Saves the uploaded XML file directly to the private hf dataset."""
20
  if xml_file is None:
21
  return "❌ Please upload an XML file first."
22
 
 
 
23
  try:
24
+ # Safely get the file path whether Gradio returned a string or an object
25
+ file_path = xml_file if isinstance(xml_file, str) else xml_file.name
26
 
27
+ # Upload directly using HfApi without copying to a local temp file first
28
  api = HfApi()
29
  api.upload_file(
30
+ path_or_fileobj=file_path,
31
  path_in_repo=THEME_FILE_NAME,
32
  repo_id=DATASET_REPO,
33
  repo_type="dataset",