Spaces:
Build error
Build error
Commit
•
1ec80ac
1
Parent(s):
47940d4
- Add title and description to both original space, and target space.
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ class SpaceBuilder:
|
|
31 |
return filtered_list
|
32 |
|
33 |
@classmethod
|
34 |
-
def file_as_a_string(cls, name_list: List[str]) -> str:
|
35 |
"""
|
36 |
Returns the file that is going to be created in the new space as string.
|
37 |
|
@@ -42,17 +42,19 @@ class SpaceBuilder:
|
|
42 |
f"import gradio as gr"
|
43 |
f"\nname_list = {name_list} "
|
44 |
f"\ninterfaces = [gr.Interface.load(name) for name in name_list]"
|
45 |
-
f"\ngr.mix.Parallel(*interfaces).launch()"
|
46 |
)
|
47 |
|
48 |
@classmethod
|
49 |
-
def create_space(cls, names: str, space_name: str, hf_token: str) -> bool:
|
50 |
"""
|
51 |
Creates the space.
|
52 |
|
53 |
-
:param
|
54 |
:param space_name: Target space_name
|
55 |
:param hf_token: HuggingFace Write Token
|
|
|
|
|
56 |
:return: True if success
|
57 |
"""
|
58 |
name_list = cls.split_space_names(names)
|
@@ -65,7 +67,7 @@ class SpaceBuilder:
|
|
65 |
repo_name = get_full_repo_name(model_id=space_name, token=hf_token)
|
66 |
|
67 |
try:
|
68 |
-
file_string = cls.file_as_a_string(name_list)
|
69 |
temp_file = open("temp_file.txt", "w")
|
70 |
temp_file.write(file_string)
|
71 |
temp_file.close()
|
@@ -179,21 +181,23 @@ class SpaceBuilder:
|
|
179 |
|
180 |
@staticmethod
|
181 |
def build_space(
|
182 |
-
space_names: str, hf_token: str, target_space_name: str,
|
183 |
) -> str:
|
184 |
"""
|
185 |
Creates a space with given inputs
|
186 |
-
:param space_names:
|
187 |
-
:param hf_token:
|
188 |
-
:param target_space_name:
|
189 |
-
:param
|
|
|
190 |
:return:
|
191 |
"""
|
192 |
if (
|
193 |
space_names == "" or space_names.isspace()
|
194 |
or hf_token == "" or hf_token.isspace()
|
195 |
or target_space_name == "" or target_space_name.isspace()
|
196 |
-
or
|
|
|
197 |
):
|
198 |
return "Please fill all the inputs"
|
199 |
if SpaceBuilder.check_space_name_availability(
|
@@ -225,8 +229,11 @@ iface = gr.Interface(
|
|
225 |
),
|
226 |
gr.inputs.Textbox(lines=1, placeholder="HuggingFace Write Token"),
|
227 |
gr.inputs.Textbox(lines=1, placeholder="Name for the target space"),
|
228 |
-
gr.inputs.Textbox(lines=1, placeholder="
|
|
|
229 |
],
|
|
|
|
|
230 |
outputs="text",
|
231 |
)
|
232 |
iface.launch()
|
|
|
31 |
return filtered_list
|
32 |
|
33 |
@classmethod
|
34 |
+
def file_as_a_string(cls, name_list: List[str], title: str, description: str) -> str:
|
35 |
"""
|
36 |
Returns the file that is going to be created in the new space as string.
|
37 |
|
|
|
42 |
f"import gradio as gr"
|
43 |
f"\nname_list = {name_list} "
|
44 |
f"\ninterfaces = [gr.Interface.load(name) for name in name_list]"
|
45 |
+
f"\ngr.mix.Parallel(*interfaces, title={title}, description={description}).launch()"
|
46 |
)
|
47 |
|
48 |
@classmethod
|
49 |
+
def create_space(cls, names: str, space_name: str, hf_token: str, title:str, description:str) -> bool:
|
50 |
"""
|
51 |
Creates the space.
|
52 |
|
53 |
+
:param names: Input space name_list
|
54 |
:param space_name: Target space_name
|
55 |
:param hf_token: HuggingFace Write Token
|
56 |
+
:param title: Target Interface Title
|
57 |
+
:param description: Target Interface Description
|
58 |
:return: True if success
|
59 |
"""
|
60 |
name_list = cls.split_space_names(names)
|
|
|
67 |
repo_name = get_full_repo_name(model_id=space_name, token=hf_token)
|
68 |
|
69 |
try:
|
70 |
+
file_string = cls.file_as_a_string(name_list, title, description)
|
71 |
temp_file = open("temp_file.txt", "w")
|
72 |
temp_file.write(file_string)
|
73 |
temp_file.close()
|
|
|
181 |
|
182 |
@staticmethod
|
183 |
def build_space(
|
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
|
191 |
+
:param interface_title: Target Interface Title
|
192 |
+
:param interface_description: Target Interface Description
|
193 |
:return:
|
194 |
"""
|
195 |
if (
|
196 |
space_names == "" or space_names.isspace()
|
197 |
or hf_token == "" or hf_token.isspace()
|
198 |
or target_space_name == "" or target_space_name.isspace()
|
199 |
+
or interface_title == "" or interface_title.isspace()
|
200 |
+
or interface_description == "" or interface_description.isspace()
|
201 |
):
|
202 |
return "Please fill all the inputs"
|
203 |
if SpaceBuilder.check_space_name_availability(
|
|
|
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()
|