John6666 commited on
Commit
2bc3926
·
verified ·
1 Parent(s): e29e7c3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +3 -2
  2. t2i_space.py +10 -7
app.py CHANGED
@@ -12,20 +12,21 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
12
  - Click "Submit" and download generated README.md and app.py.
13
  - [Create your new Gradio space](https://huggingface.co/new-space) with blank.
14
  - Upload README.md and app.py to your space.
15
- - If you got 500 error, it happens often, just restart space.
16
  - If it does not work no matter how many times you try, there is often a problem with the settings of the original repo itself, or there is no generation function.
17
  """
18
  )
19
  with gr.Column():
20
  repo_id = gr.Textbox(label="Model repo ID", placeholder="username/modelname", value="", max_lines=1)
21
  gradio_version = gr.Textbox(label="Gradio version", placeholder="username/modelname", value="4.44.0", max_lines=1)
 
22
  run_button = gr.Button(value="Submit")
23
  space_file = gr.Files(label="Output", interactive=False)
24
 
25
  gr.on(
26
  triggers=[repo_id.submit, run_button.click],
27
  fn=get_t2i_space_contents,
28
- inputs=[repo_id, gradio_version],
29
  outputs=[space_file],
30
  )
31
 
 
12
  - Click "Submit" and download generated README.md and app.py.
13
  - [Create your new Gradio space](https://huggingface.co/new-space) with blank.
14
  - Upload README.md and app.py to your space.
15
+ - If you got 500 / 504 error, it happens often, just restart space.
16
  - If it does not work no matter how many times you try, there is often a problem with the settings of the original repo itself, or there is no generation function.
17
  """
18
  )
19
  with gr.Column():
20
  repo_id = gr.Textbox(label="Model repo ID", placeholder="username/modelname", value="", max_lines=1)
21
  gradio_version = gr.Textbox(label="Gradio version", placeholder="username/modelname", value="4.44.0", max_lines=1)
22
+ private_ok = gr.Checkbox("Allow private repo", value=True)
23
  run_button = gr.Button(value="Submit")
24
  space_file = gr.Files(label="Output", interactive=False)
25
 
26
  gr.on(
27
  triggers=[repo_id.submit, run_button.click],
28
  fn=get_t2i_space_contents,
29
+ inputs=[repo_id, gradio_version, private_ok],
30
  outputs=[space_file],
31
  )
32
 
t2i_space.py CHANGED
@@ -1,6 +1,6 @@
1
  from pathlib import Path
2
  import os
3
-
4
 
5
  def is_repo_name(s):
6
  import re
@@ -26,13 +26,16 @@ def is_repo_t2i(repo_id):
26
  if model_info.pipeline_tag == "text-to-image": return True
27
  else: return False
28
  except Exception as e:
29
- print(f"Error: Failed to connect {repo_id}. ")
30
  return True # for safe
31
 
32
 
33
- def save_space_contents(repo_id: str, gradio_version: str, dir: str):
34
- if not is_repo_name(repo_id) or not is_repo_exists(repo_id): # or not is_repo_t2i(repo_id)
35
- print(f"Error: Invalid repo ID: {repo_id}. ")
 
 
 
36
  return []
37
  os.makedirs(dir, exist_ok=True)
38
  model_name = repo_id.split("/")[-1]
@@ -63,5 +66,5 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
63
  return [app_path, readme_path]
64
 
65
 
66
- def get_t2i_space_contents(repo_id: str, gradio_version: str):
67
- return save_space_contents(repo_id, gradio_version, "./temp/")
 
1
  from pathlib import Path
2
  import os
3
+ import gradio as gr
4
 
5
  def is_repo_name(s):
6
  import re
 
26
  if model_info.pipeline_tag == "text-to-image": return True
27
  else: return False
28
  except Exception as e:
29
+ print(f"Error: Failed to connect {repo_id}.")
30
  return True # for safe
31
 
32
 
33
+ def save_space_contents(repo_id: str, gradio_version: str, private_ok: bool, dir: str):
34
+ if not is_repo_name(repo_id): # or not is_repo_t2i(repo_id)
35
+ gr.Info(f"Error: Invalid repo ID: {repo_id}.")
36
+ return []
37
+ if not private_ok and not is_repo_exists(repo_id):
38
+ gr.Info(f"Error: Repo doesn't exist: {repo_id}.")
39
  return []
40
  os.makedirs(dir, exist_ok=True)
41
  model_name = repo_id.split("/")[-1]
 
66
  return [app_path, readme_path]
67
 
68
 
69
+ def get_t2i_space_contents(repo_id: str, gradio_version: str, private_ok: bool):
70
+ return save_space_contents(repo_id, gradio_version, private_ok, "./temp/")