Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
from app_logic import build_space_from_image
|
3 |
|
4 |
def main_ui():
|
5 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
)
|
16 |
|
17 |
with gr.Row():
|
18 |
with gr.Column(scale=1):
|
@@ -27,8 +26,11 @@ def main_ui():
|
|
27 |
type="password",
|
28 |
placeholder="Enter your write-permission token"
|
29 |
)
|
|
|
|
|
|
|
|
|
30 |
space_name_input = gr.Textbox(label="New Space Name", placeholder="e.g., my-new-app")
|
31 |
-
owner_input = gr.Textbox(label="Owner (Username/Org)", placeholder="Leave blank to use your username")
|
32 |
sdk_input = gr.Dropdown(
|
33 |
label="Space SDK",
|
34 |
choices=["gradio", "streamlit", "docker", "static"],
|
@@ -43,7 +45,26 @@ def main_ui():
|
|
43 |
gr.Markdown("### Build Status & Result")
|
44 |
output_status_md = gr.Markdown(label="Result")
|
45 |
|
46 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
create_button.click(
|
48 |
fn=build_space_from_image,
|
49 |
inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
+
from app_logic import build_space_from_image, get_username_from_token
|
3 |
|
4 |
def main_ui():
|
5 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="Image-to-Space Builder") as demo:
|
6 |
+
gr.Markdown(
|
7 |
+
"""
|
8 |
+
# 🖼️ Image-to-Space Builder
|
9 |
+
## Create a new Hugging Face Space directly from a repo-embedded image.
|
10 |
+
|
11 |
+
This tool extracts the file structure and content from an encrypted image (created with a tool like KeyLock)
|
12 |
+
and uses it to build and deploy a new Hugging Face Space.
|
13 |
+
"""
|
14 |
+
)
|
|
|
15 |
|
16 |
with gr.Row():
|
17 |
with gr.Column(scale=1):
|
|
|
26 |
type="password",
|
27 |
placeholder="Enter your write-permission token"
|
28 |
)
|
29 |
+
owner_input = gr.Textbox(
|
30 |
+
label="Owner (Username/Org)",
|
31 |
+
placeholder="Autofills from token if left blank" # Updated placeholder
|
32 |
+
)
|
33 |
space_name_input = gr.Textbox(label="New Space Name", placeholder="e.g., my-new-app")
|
|
|
34 |
sdk_input = gr.Dropdown(
|
35 |
label="Space SDK",
|
36 |
choices=["gradio", "streamlit", "docker", "static"],
|
|
|
45 |
gr.Markdown("### Build Status & Result")
|
46 |
output_status_md = gr.Markdown(label="Result")
|
47 |
|
48 |
+
# --- Wrapper function for better UX ---
|
49 |
+
def autofill_owner_if_empty(api_token, current_owner):
|
50 |
+
"""
|
51 |
+
Checks if the owner field is empty. If so, it tries to fetch the username.
|
52 |
+
This prevents overwriting a manually entered organization or username.
|
53 |
+
"""
|
54 |
+
# Only run the API call if the owner field is currently empty
|
55 |
+
if not current_owner.strip():
|
56 |
+
return get_username_from_token(api_token)
|
57 |
+
# If the user has already typed something, leave it alone.
|
58 |
+
return current_owner
|
59 |
+
|
60 |
+
# --- NEW Event Handler for Autofill ---
|
61 |
+
api_token_input.blur(
|
62 |
+
fn=autofill_owner_if_empty,
|
63 |
+
inputs=[api_token_input, owner_input], # Pass both token and the current owner value
|
64 |
+
outputs=[owner_input]
|
65 |
+
)
|
66 |
+
|
67 |
+
# --- Main "Create" Button Event Handler (Unchanged) ---
|
68 |
create_button.click(
|
69 |
fn=build_space_from_image,
|
70 |
inputs=[
|