Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(), 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):
|
| 18 |
+
gr.Markdown("### 1. Upload Your Repo Image")
|
| 19 |
+
repo_image_input = gr.Image(label="Repo-Embedded Image (PNG)", type="pil")
|
| 20 |
+
image_password_input = gr.Textbox(label="Image Decryption Password", type="password")
|
| 21 |
+
|
| 22 |
+
gr.Markdown("---")
|
| 23 |
+
gr.Markdown("### 2. Configure Your New Space")
|
| 24 |
+
api_token_input = gr.Textbox(
|
| 25 |
+
label="Hugging Face API Token (hf_xxx)",
|
| 26 |
+
type="password",
|
| 27 |
+
placeholder="Enter your write-permission token"
|
| 28 |
+
)
|
| 29 |
+
space_name_input = gr.Textbox(label="New Space Name", placeholder="e.g., my-new-app")
|
| 30 |
+
owner_input = gr.Textbox(label="Owner (Username/Org)", placeholder="Leave blank to use your username")
|
| 31 |
+
sdk_input = gr.Dropdown(
|
| 32 |
+
label="Space SDK",
|
| 33 |
+
choices=["gradio", "streamlit", "docker", "static"],
|
| 34 |
+
value="gradio"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
gr.Markdown("---")
|
| 38 |
+
gr.Markdown("### 3. Build It!")
|
| 39 |
+
create_button = gr.Button("Create Space from Image", variant="primary")
|
| 40 |
+
|
| 41 |
+
with gr.Column(scale=2):
|
| 42 |
+
gr.Markdown("### Build Status & Result")
|
| 43 |
+
output_status_md = gr.Markdown(label="Result")
|
| 44 |
+
|
| 45 |
+
# --- Event Handler ---
|
| 46 |
+
create_button.click(
|
| 47 |
+
fn=build_space_from_image,
|
| 48 |
+
inputs=[
|
| 49 |
+
api_token_input,
|
| 50 |
+
repo_image_input,
|
| 51 |
+
image_password_input,
|
| 52 |
+
space_name_input,
|
| 53 |
+
owner_input,
|
| 54 |
+
sdk_input
|
| 55 |
+
],
|
| 56 |
+
outputs=[output_status_md]
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
return demo
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo = main_ui()
|
| 63 |
+
demo.launch(show_error=True)
|