anzorq commited on
Commit
38729c1
β€’
1 Parent(s): 31f3dc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -36,7 +36,7 @@ def on_token_change(token):
36
 
37
  return gr.update(visible=bool(model_names)), gr.update(visible=bool(model_names)), gr.update(choices=model_names), gr.update(visible=bool(model_names)), gr.update(value=error_str(error))
38
 
39
- def create_and_push(model_id, title, description, prefix, update, token):
40
 
41
  try:
42
 
@@ -50,7 +50,7 @@ def create_and_push(model_id, title, description, prefix, update, token):
50
  )
51
 
52
  # 2. Replace the name, title, and description in the template
53
- with open("template/app.py", "r") as f:
54
  app = f.read()
55
  app = app.replace("$model_id", model_id)
56
  app = app.replace("$title", title)
@@ -71,13 +71,14 @@ def create_and_push(model_id, title, description, prefix, update, token):
71
  )
72
 
73
  # 5. Upload template/requirements.txt to the space
74
- api.upload_file(
75
- path_or_fileobj="template/requirements.txt",
76
- path_in_repo="requirements.txt",
77
- repo_id=model_id,
78
- token=token,
79
- repo_type="space",
80
- )
 
81
 
82
  # 5. Delete the app.py file
83
  os.remove("app.py")
@@ -127,6 +128,13 @@ with gr.Blocks() as demo:
127
  description = gr.Textbox(label="Description", placeholder="e.g. Demo for my awesome Diffusers model")
128
  prefix = gr.Textbox(label="Prefix tokens", placeholder="Tokens that are required to be present in the prompt, e.g. `rick and morty style`")
129
  update = gr.Checkbox(label="Update the space if it already exists?")
 
 
 
 
 
 
 
130
  brn_create = gr.Button("Create the space")
131
 
132
  error_output = gr.Markdown(label="Output")
@@ -148,7 +156,7 @@ with gr.Blocks() as demo:
148
 
149
  brn_create.click(
150
  fn=create_and_push,
151
- inputs=[radio_model_names, title, description, prefix, update, input_token],
152
  outputs=[error_output],
153
  scroll_to_output=True
154
  )
 
36
 
37
  return gr.update(visible=bool(model_names)), gr.update(visible=bool(model_names)), gr.update(choices=model_names), gr.update(visible=bool(model_names)), gr.update(value=error_str(error))
38
 
39
+ def create_and_push(space_type, model_id, title, description, prefix, update, token):
40
 
41
  try:
42
 
 
50
  )
51
 
52
  # 2. Replace the name, title, and description in the template
53
+ with open("template/app_simple.py" if space_type == "Simple" else "template/app_advanced.py", "r") as f:
54
  app = f.read()
55
  app = app.replace("$model_id", model_id)
56
  app = app.replace("$title", title)
 
71
  )
72
 
73
  # 5. Upload template/requirements.txt to the space
74
+ if space_type == "Advanced":
75
+ api.upload_file(
76
+ path_or_fileobj="template/requirements.txt",
77
+ path_in_repo="requirements.txt",
78
+ repo_id=model_id,
79
+ token=token,
80
+ repo_type="space",
81
+ )
82
 
83
  # 5. Delete the app.py file
84
  os.remove("app.py")
 
128
  description = gr.Textbox(label="Description", placeholder="e.g. Demo for my awesome Diffusers model")
129
  prefix = gr.Textbox(label="Prefix tokens", placeholder="Tokens that are required to be present in the prompt, e.g. `rick and morty style`")
130
  update = gr.Checkbox(label="Update the space if it already exists?")
131
+
132
+ # text explainig the difference between simple and advanced types: simple runs on GPU using HF inference API, advanced runs on CPU by default with the option to upgrade to GPU:
133
+ gr.Markdown("""#### Choose space type
134
+ - **Simple** - Runs on GPU using Hugging Face inference API, but you cannot control image generation parameters.
135
+ - **Advanced** - Runs on CPU by default, with the option to upgrade to GPU. You can control image generation parameters: guidance, number of steps, image size, etc. Also supports **image-to-image** generation.""")
136
+ space_type =gr.Radio(label="Space type", choices=["Simple", "Advanced"], value="Simple")
137
+
138
  brn_create = gr.Button("Create the space")
139
 
140
  error_output = gr.Markdown(label="Output")
 
156
 
157
  brn_create.click(
158
  fn=create_and_push,
159
+ inputs=[space_type, radio_model_names, title, description, prefix, update, input_token],
160
  outputs=[error_output],
161
  scroll_to_output=True
162
  )