omerXfaruq commited on
Commit
8f8e04c
1 Parent(s): f54c35a

- add __name__ check

Browse files
Files changed (1) hide show
  1. app.py +32 -33
app.py CHANGED
@@ -176,6 +176,7 @@ class SpaceBuilder:
176
  print("The space name is available")
177
  return True
178
  except Exception as ex:
 
179
  cls.error_message = "Can not send a request to https://huggingface.co"
180
  return False
181
 
@@ -184,7 +185,8 @@ class SpaceBuilder:
184
  space_names: str, hf_token: str, target_space_name: str, interface_title: str, interface_description: str
185
  ) -> str:
186
  """
187
- Creates a space with given inputs
 
188
  :param space_names: Multiple space names split with new lines
189
  :param hf_token: HuggingFace token
190
  :param target_space_name: Target Space Name
@@ -200,40 +202,37 @@ class SpaceBuilder:
200
  or interface_description == "" or interface_description.isspace()
201
  ):
202
  return "Please fill all the inputs"
203
- if SpaceBuilder.check_space_name_availability(
204
- hf_token=hf_token, space_name=target_space_name
 
 
 
 
205
  ):
206
- if SpaceBuilder.load_and_check_spaces(names=space_names):
207
- if SpaceBuilder.create_space(
208
- names=space_names, space_name=target_space_name, hf_token=hf_token, title=interface_title, description=interface_description
209
- ):
210
- return SpaceBuilder.url
211
- else:
212
- return SpaceBuilder.error_message
213
- else:
214
- return SpaceBuilder.error_message
215
- else:
216
  return SpaceBuilder.error_message
217
 
 
218
 
219
- iface = gr.Interface(
220
- fn=SpaceBuilder.build_space,
221
- inputs=[
222
- gr.inputs.Textbox(
223
- lines=4,
224
- placeholder=(
225
- f"Drop space links at each line and I will create a new space comparing them. ie:"
226
- f"\nspaces/Norod78/ComicsHeroHD"
227
- f"\nspaces/Amrrs/gradio-sentiment-analyzer"
 
 
 
228
  ),
229
- ),
230
- gr.inputs.Textbox(lines=1, placeholder="HuggingFace Write Token"),
231
- gr.inputs.Textbox(lines=1, placeholder="Name for the target space"),
232
- gr.inputs.Textbox(lines=1, placeholder="Title for the target space interface"),
233
- gr.inputs.Textbox(lines=1, placeholder="Description for the target space interface"),
234
- ],
235
- title="Space that builds another Space",
236
- description="I can create another space which will compare the spaces you provide to me",
237
- outputs="text",
238
- )
239
- iface.launch()
 
176
  print("The space name is available")
177
  return True
178
  except Exception as ex:
179
+ print(ex)
180
  cls.error_message = "Can not send a request to https://huggingface.co"
181
  return False
182
 
 
185
  space_names: str, hf_token: str, target_space_name: str, interface_title: str, interface_description: str
186
  ) -> str:
187
  """
188
+ Creates a space with given input spaces.
189
+
190
  :param space_names: Multiple space names split with new lines
191
  :param hf_token: HuggingFace token
192
  :param target_space_name: Target Space Name
 
202
  or interface_description == "" or interface_description.isspace()
203
  ):
204
  return "Please fill all the inputs"
205
+ if not SpaceBuilder.check_space_name_availability(hf_token=hf_token, space_name=target_space_name):
206
+ return SpaceBuilder.error_message
207
+ if not SpaceBuilder.load_and_check_spaces(names=space_names):
208
+ return SpaceBuilder.error_message
209
+ if not SpaceBuilder.create_space(
210
+ names=space_names, space_name=target_space_name, hf_token=hf_token, title=interface_title, description=interface_description
211
  ):
 
 
 
 
 
 
 
 
 
 
212
  return SpaceBuilder.error_message
213
 
214
+ return SpaceBuilder.url
215
 
216
+
217
+ if __name__ == "__main__":
218
+ iface = gr.Interface(
219
+ fn=SpaceBuilder.build_space,
220
+ inputs=[
221
+ gr.inputs.Textbox(
222
+ lines=4,
223
+ placeholder=(
224
+ f"Drop space links at each line and I will create a new space comparing them. ie:"
225
+ f"\nspaces/Norod78/ComicsHeroHD"
226
+ f"\nspaces/Amrrs/gradio-sentiment-analyzer"
227
+ ),
228
  ),
229
+ gr.inputs.Textbox(lines=1, placeholder="HuggingFace Write Token"),
230
+ gr.inputs.Textbox(lines=1, placeholder="Name for the target space"),
231
+ gr.inputs.Textbox(lines=1, placeholder="Title for the target space interface"),
232
+ gr.inputs.Textbox(lines=1, placeholder="Description for the target space interface"),
233
+ ],
234
+ title="Space that builds another Space",
235
+ description="I can create another space which will compare the spaces you provide to me",
236
+ outputs="text",
237
+ )
238
+ iface.launch()