Spaces:
Running
Running
Upload 5 files
Browse files- README.md +2 -2
- app.py +4 -3
- t2i_space.py +10 -11
- template/README.md +12 -0
- template/app.py +3 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title: Gradio
|
3 |
emoji: 🐶
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
1 |
---
|
2 |
+
title: Gradio Demo Space creation helper
|
3 |
emoji: 🐶
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.41.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -4,11 +4,11 @@ from t2i_space import get_t2i_space_contents
|
|
4 |
css = """"""
|
5 |
|
6 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
|
7 |
-
gr.Markdown("# Gradio
|
8 |
gr.Markdown(
|
9 |
f"""
|
10 |
**The steps are the following**:
|
11 |
-
- Input
|
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.
|
@@ -18,13 +18,14 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
|
|
18 |
)
|
19 |
with gr.Column():
|
20 |
repo_id = gr.Textbox(label="Model repo ID", placeholder="username/modelname", value="", max_lines=1)
|
|
|
21 |
run_button = gr.Button(value="Submit")
|
22 |
space_file = gr.Files(label="Output", interactive=False)
|
23 |
|
24 |
gr.on(
|
25 |
triggers=[repo_id.submit, run_button.click],
|
26 |
fn=get_t2i_space_contents,
|
27 |
-
inputs=[repo_id],
|
28 |
outputs=[space_file],
|
29 |
)
|
30 |
|
|
|
4 |
css = """"""
|
5 |
|
6 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
|
7 |
+
gr.Markdown("# Gradio Demo Space creation helper")
|
8 |
gr.Markdown(
|
9 |
f"""
|
10 |
**The steps are the following**:
|
11 |
+
- Input model Repo ID which you want to use. e.g. 'user/model'.
|
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.
|
|
|
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 |
|
t2i_space.py
CHANGED
@@ -14,7 +14,7 @@ def is_repo_exists(repo_id):
|
|
14 |
if api.repo_exists(repo_id=repo_id, repo_type="model"): return True
|
15 |
else: return False
|
16 |
except Exception as e:
|
17 |
-
print(f"Error: Failed to connect {repo_id}.
|
18 |
return True # for safe
|
19 |
|
20 |
|
@@ -22,7 +22,7 @@ def is_repo_t2i(repo_id):
|
|
22 |
from huggingface_hub import HfApi
|
23 |
api = HfApi()
|
24 |
try:
|
25 |
-
model_info =
|
26 |
if model_info.pipeline_tag == "text-to-image": return True
|
27 |
else: return False
|
28 |
except Exception as e:
|
@@ -30,26 +30,25 @@ def is_repo_t2i(repo_id):
|
|
30 |
return True # for safe
|
31 |
|
32 |
|
33 |
-
def save_space_contents(repo_id: 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]
|
39 |
app_py = f"""import gradio as gr
|
40 |
-
|
41 |
-
demo.launch()
|
42 |
"""
|
43 |
readme_md = f"""---
|
44 |
-
title: {model_name}
|
45 |
emoji: 🖼
|
46 |
colorFrom: purple
|
47 |
colorTo: red
|
48 |
sdk: gradio
|
49 |
-
sdk_version:
|
50 |
app_file: app.py
|
51 |
pinned: false
|
52 |
-
short_description: {repo_id} | Text-to-Image
|
53 |
---
|
54 |
|
55 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
@@ -64,5 +63,5 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
64 |
return [app_path, readme_path]
|
65 |
|
66 |
|
67 |
-
def get_t2i_space_contents(repo_id: str):
|
68 |
-
return save_space_contents(repo_id, "./temp/")
|
|
|
14 |
if api.repo_exists(repo_id=repo_id, repo_type="model"): return True
|
15 |
else: return False
|
16 |
except Exception as e:
|
17 |
+
print(f"Error: Failed to connect {repo_id}.")
|
18 |
return True # for safe
|
19 |
|
20 |
|
|
|
22 |
from huggingface_hub import HfApi
|
23 |
api = HfApi()
|
24 |
try:
|
25 |
+
model_info = api.repo_info(repo_id=repo_id, repo_type="model")
|
26 |
if model_info.pipeline_tag == "text-to-image": return True
|
27 |
else: return False
|
28 |
except Exception as e:
|
|
|
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]
|
39 |
app_py = f"""import gradio as gr
|
40 |
+
import os
|
41 |
+
demo = gr.load("{repo_id}", src="models", hf_token=os.environ.get("HF_TOKEN")).launch()
|
42 |
"""
|
43 |
readme_md = f"""---
|
44 |
+
title: {model_name} Demo
|
45 |
emoji: 🖼
|
46 |
colorFrom: purple
|
47 |
colorTo: red
|
48 |
sdk: gradio
|
49 |
+
sdk_version: {gradio_version}
|
50 |
app_file: app.py
|
51 |
pinned: false
|
|
|
52 |
---
|
53 |
|
54 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
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/")
|
template/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: {model_name} Demo
|
3 |
+
emoji: 🖼
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: {gradio_version}
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
template/app.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
demo = gr.load("{repo_id}", src="models", hf_token=os.environ.get("HF_TOKEN")).launch()
|