akhaliq HF Staff commited on
Commit
b301cbe
·
1 Parent(s): 40e81c4

use gradio 6 in readme

Browse files
Files changed (1) hide show
  1. backend_deploy.py +16 -3
backend_deploy.py CHANGED
@@ -299,7 +299,7 @@ def detect_sdk_from_code(code: str, language: str) -> str:
299
  return "gradio" # Default
300
 
301
 
302
- def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None) -> None:
303
  """
304
  Download existing README, add anycoder tag and app_port if needed, and upload back.
305
  Preserves all existing README content and frontmatter.
@@ -308,6 +308,7 @@ def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None
308
  api: HuggingFace API client
309
  repo_id: Repository ID (username/space-name)
310
  app_port: Optional port number to set for Docker spaces (e.g., 7860)
 
311
  """
312
  try:
313
  import tempfile
@@ -345,6 +346,17 @@ def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None
345
  if app_port is not None and 'app_port:' not in frontmatter:
346
  frontmatter += f'\napp_port: {app_port}'
347
 
 
 
 
 
 
 
 
 
 
 
 
348
  # Reconstruct the README
349
  new_content = f"---\n{frontmatter}\n---{body}"
350
  else:
@@ -353,7 +365,8 @@ def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None
353
  else:
354
  # No frontmatter, add it at the beginning
355
  app_port_line = f'\napp_port: {app_port}' if app_port else ''
356
- new_content = f"---\ntags:\n- anycoder{app_port_line}\n---\n\n{content}"
 
357
 
358
  # Upload the modified README
359
  with tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding='utf-8') as f:
@@ -1044,7 +1057,7 @@ def deploy_to_huggingface_space(
1044
  import time
1045
  if not is_update:
1046
  time.sleep(2) # Give HF time to generate README for new spaces
1047
- add_anycoder_tag_to_readme(api, repo_id, app_port)
1048
  except Exception as e:
1049
  # Don't fail deployment if README modification fails
1050
  print(f"Warning: Could not add anycoder tag to README: {e}")
 
299
  return "gradio" # Default
300
 
301
 
302
+ def add_anycoder_tag_to_readme(api, repo_id: str, app_port: Optional[int] = None, sdk: Optional[str] = None) -> None:
303
  """
304
  Download existing README, add anycoder tag and app_port if needed, and upload back.
305
  Preserves all existing README content and frontmatter.
 
308
  api: HuggingFace API client
309
  repo_id: Repository ID (username/space-name)
310
  app_port: Optional port number to set for Docker spaces (e.g., 7860)
311
+ sdk: Optional SDK type (e.g., 'gradio', 'streamlit', 'docker', 'static')
312
  """
313
  try:
314
  import tempfile
 
346
  if app_port is not None and 'app_port:' not in frontmatter:
347
  frontmatter += f'\napp_port: {app_port}'
348
 
349
+ # For Gradio spaces, always set sdk_version to 6.0.2
350
+ if sdk == 'gradio':
351
+ if 'sdk_version:' in frontmatter:
352
+ # Update existing sdk_version
353
+ frontmatter = re.sub(r'sdk_version:\s*[^\n]+', 'sdk_version: 6.0.2', frontmatter)
354
+ print(f"[README] Updated sdk_version to 6.0.2 for Gradio space")
355
+ else:
356
+ # Add sdk_version
357
+ frontmatter += '\nsdk_version: 6.0.2'
358
+ print(f"[README] Added sdk_version: 6.0.2 for Gradio space")
359
+
360
  # Reconstruct the README
361
  new_content = f"---\n{frontmatter}\n---{body}"
362
  else:
 
365
  else:
366
  # No frontmatter, add it at the beginning
367
  app_port_line = f'\napp_port: {app_port}' if app_port else ''
368
+ sdk_version_line = '\nsdk_version: 6.0.2' if sdk == 'gradio' else ''
369
+ new_content = f"---\ntags:\n- anycoder{app_port_line}{sdk_version_line}\n---\n\n{content}"
370
 
371
  # Upload the modified README
372
  with tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding='utf-8') as f:
 
1057
  import time
1058
  if not is_update:
1059
  time.sleep(2) # Give HF time to generate README for new spaces
1060
+ add_anycoder_tag_to_readme(api, repo_id, app_port, sdk)
1061
  except Exception as e:
1062
  # Don't fail deployment if README modification fails
1063
  print(f"Warning: Could not add anycoder tag to README: {e}")