soiz1 commited on
Commit
aa47dbe
Β·
verified Β·
1 Parent(s): 319b167

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -5,6 +5,7 @@ from slugify import slugify
5
  import uuid
6
  import os
7
  import re
 
8
 
9
  # Function to extract metadata from README.md file
10
  def extract_from_readme(readme_path):
@@ -25,34 +26,19 @@ def extract_from_readme(readme_path):
25
  port = match_port.group(1).strip()
26
  return title, description, port
27
 
 
28
  # Main function to clone a Git repo and create a Hugging Face repo
29
  def clone_and_create(profile: gr.OAuthProfile, token: gr.OAuthToken,
30
  repo_url, repo_type, private, space_sdk, sdk_version,
31
- space_id, space_title, space_description):
32
-
33
- # README.md γ‹γ‚‰ζƒ…ε ±γ‚’ζŠ½ε‡Ίγ™γ‚‹ι–’ζ•°
34
- def extract_from_readme(readme_path):
35
- import re
36
- title = None
37
- description = None
38
- port = None
39
- if os.path.exists(readme_path):
40
- with open(readme_path, encoding="utf-8") as f:
41
- content = f.read()
42
- match_title = re.search(r'title:\s*(.*)', content)
43
- match_desc = re.search(r'short_description:\s*(.*)', content)
44
- match_port = re.search(r'app_port:\s*(\d+)', content)
45
- if match_title:
46
- title = match_title.group(1).strip()
47
- if match_desc:
48
- description = match_desc.group(1).strip()
49
- if match_port:
50
- port = match_port.group(1).strip()
51
- return title, description, port
52
 
53
  folder = str(uuid.uuid4()) # ユニークγͺγƒ•γ‚©γƒ«γƒ€εδ½œζˆ
54
  Repo.clone_from(repo_url, folder) # Gitγƒͺγƒγ‚Έγƒˆγƒͺをクローン
55
 
 
 
 
 
56
  hf_api = HfApi(token=token.token)
57
 
58
  # README.md からθ‡ͺ動情報取得
@@ -116,6 +102,7 @@ with gr.Blocks() as demo:
116
  repo_url = gr.Textbox(label="Git Repository URL (e.g., GitHub)")
117
  repo_type = gr.Dropdown(choices=["space", "dataset", "model"], value="space", label="Hugging Face repo type")
118
  private = gr.Checkbox(label="Make Private", value=False)
 
119
  space_sdk = gr.Dropdown(choices=["gradio", "streamlit", "docker", "static"], label="Space SDK", visible=True)
120
  sdk_version = gr.Textbox(label="SDK Version (optional)", visible=True)
121
  space_id = gr.Textbox(label="Hugging Face ID (auto if blank)")
@@ -141,7 +128,7 @@ with gr.Blocks() as demo:
141
  btn = gr.Button("Clone and Create!")
142
  btn.click(
143
  fn=clone_and_create,
144
- inputs=[repo_url, repo_type, private, space_sdk, sdk_version, space_id, space_title, space_description],
145
  outputs=output
146
  )
147
 
 
5
  import uuid
6
  import os
7
  import re
8
+ import subprocess
9
 
10
  # Function to extract metadata from README.md file
11
  def extract_from_readme(readme_path):
 
26
  port = match_port.group(1).strip()
27
  return title, description, port
28
 
29
+
30
  # Main function to clone a Git repo and create a Hugging Face repo
31
  def clone_and_create(profile: gr.OAuthProfile, token: gr.OAuthToken,
32
  repo_url, repo_type, private, space_sdk, sdk_version,
33
+ space_id, space_title, space_description, include_submodules):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  folder = str(uuid.uuid4()) # ユニークγͺγƒ•γ‚©γƒ«γƒ€εδ½œζˆ
36
  Repo.clone_from(repo_url, folder) # Gitγƒͺγƒγ‚Έγƒˆγƒͺをクローン
37
 
38
+ # γ‚΅γƒ–γƒ’γ‚Έγƒ₯γƒΌγƒ«γ‚’ε«γ‚γ‚‹ε ΄εˆ
39
+ if include_submodules:
40
+ subprocess.run(["git", "submodule", "update", "--init", "--recursive"], cwd=folder, check=True)
41
+
42
  hf_api = HfApi(token=token.token)
43
 
44
  # README.md からθ‡ͺ動情報取得
 
102
  repo_url = gr.Textbox(label="Git Repository URL (e.g., GitHub)")
103
  repo_type = gr.Dropdown(choices=["space", "dataset", "model"], value="space", label="Hugging Face repo type")
104
  private = gr.Checkbox(label="Make Private", value=False)
105
+ include_submodules = gr.Checkbox(label="Include submodules", value=False) # 追加
106
  space_sdk = gr.Dropdown(choices=["gradio", "streamlit", "docker", "static"], label="Space SDK", visible=True)
107
  sdk_version = gr.Textbox(label="SDK Version (optional)", visible=True)
108
  space_id = gr.Textbox(label="Hugging Face ID (auto if blank)")
 
128
  btn = gr.Button("Clone and Create!")
129
  btn.click(
130
  fn=clone_and_create,
131
+ inputs=[repo_url, repo_type, private, space_sdk, sdk_version, space_id, space_title, space_description, include_submodules],
132
  outputs=output
133
  )
134