Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -146,10 +146,10 @@ class SpaceCreatorApp:
|
|
| 146 |
def _create_status_message(self, msg_type, message):
|
| 147 |
"""Create formatted status message"""
|
| 148 |
icons = {
|
| 149 |
-
"success": "
|
| 150 |
-
"error": "
|
| 151 |
-
"warning": "
|
| 152 |
-
"info": "
|
| 153 |
}
|
| 154 |
colors = {
|
| 155 |
"success": "#10B981",
|
|
@@ -160,10 +160,10 @@ class SpaceCreatorApp:
|
|
| 160 |
|
| 161 |
return f'''
|
| 162 |
<div class="status-message {msg_type}">
|
| 163 |
-
<span
|
| 164 |
{icons[msg_type]}
|
| 165 |
</span>
|
| 166 |
-
<span
|
| 167 |
</div>
|
| 168 |
'''
|
| 169 |
|
|
@@ -172,74 +172,448 @@ def create_app():
|
|
| 172 |
"""Create the Gradio application interface"""
|
| 173 |
app = SpaceCreatorApp()
|
| 174 |
|
| 175 |
-
# Use a
|
| 176 |
theme = gr.themes.Base(
|
| 177 |
primary_hue="blue",
|
| 178 |
secondary_hue="gray",
|
| 179 |
neutral_hue="gray",
|
| 180 |
-
font=
|
| 181 |
)
|
| 182 |
|
| 183 |
with gr.Blocks(
|
| 184 |
title="Hugging Face Space Creator",
|
| 185 |
theme=theme,
|
| 186 |
-
css="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
) as demo:
|
| 188 |
|
| 189 |
-
#
|
| 190 |
-
gr.HTML('<link href="https://fonts.googleapis.com/
|
| 191 |
|
| 192 |
-
# Header
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
current_step = gr.State(1)
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
-
# Main
|
| 202 |
-
with gr.Column(scale=3):
|
| 203 |
-
# Step 1: Code Input
|
| 204 |
with gr.Group(visible=True) as step1_group:
|
| 205 |
gr.Markdown("### Step 1: Provide Your Code")
|
| 206 |
|
| 207 |
with gr.Tabs():
|
| 208 |
-
with gr.Tab("Upload File"
|
| 209 |
file_input = gr.File(
|
| 210 |
label="Upload Python or Jupyter Notebook",
|
| 211 |
file_types=SUPPORTED_EXTENSIONS,
|
| 212 |
type="filepath"
|
| 213 |
)
|
| 214 |
|
| 215 |
-
with gr.Tab("Paste Code"
|
| 216 |
text_input = gr.Textbox(
|
| 217 |
label="Python Code",
|
| 218 |
-
lines=
|
| 219 |
-
placeholder="# Paste your Python code here...\n
|
| 220 |
elem_id="code_editor"
|
| 221 |
)
|
| 222 |
|
| 223 |
-
gr.Markdown("### Step
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
info="Required for AI-powered conversion"
|
| 231 |
-
)
|
| 232 |
|
| 233 |
-
# API
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
elem_id="convert_btn"
|
| 242 |
-
)
|
| 243 |
|
| 244 |
# Step 2: Generated Files
|
| 245 |
with gr.Group(visible=False) as step2_group:
|
|
@@ -247,49 +621,51 @@ def create_app():
|
|
| 247 |
|
| 248 |
with gr.Row():
|
| 249 |
with gr.Column():
|
|
|
|
| 250 |
app_py_download = gr.File(
|
| 251 |
-
label="app.py",
|
| 252 |
file_types=[".py"],
|
| 253 |
interactive=False
|
| 254 |
)
|
| 255 |
|
| 256 |
with gr.Column():
|
|
|
|
| 257 |
requirements_download = gr.File(
|
| 258 |
-
label="requirements.txt",
|
| 259 |
file_types=[".txt"],
|
| 260 |
interactive=False
|
| 261 |
)
|
| 262 |
|
| 263 |
with gr.Column():
|
|
|
|
| 264 |
readme_download = gr.File(
|
| 265 |
-
label="README.md",
|
| 266 |
file_types=[".md"],
|
| 267 |
interactive=False
|
| 268 |
)
|
| 269 |
|
| 270 |
-
gr.Markdown("### Step
|
| 271 |
|
| 272 |
with gr.Row():
|
| 273 |
with gr.Column():
|
| 274 |
hf_token = gr.Textbox(
|
| 275 |
label="Hugging Face Token",
|
| 276 |
type="password",
|
| 277 |
-
placeholder="Enter your Hugging Face token
|
| 278 |
info="Required for deployment"
|
| 279 |
)
|
| 280 |
|
| 281 |
with gr.Column():
|
| 282 |
space_name = gr.Textbox(
|
| 283 |
label="Space Name",
|
| 284 |
-
placeholder="my-gradio-
|
| 285 |
info="Lowercase letters, numbers, and hyphens only"
|
| 286 |
)
|
| 287 |
|
| 288 |
deploy_mode = gr.Radio(
|
| 289 |
choices=["Download Only", "Deploy to Hugging Face Space"],
|
| 290 |
label="Select Action",
|
| 291 |
-
value="Download Only"
|
| 292 |
-
elem_id="deploy_mode"
|
| 293 |
)
|
| 294 |
|
| 295 |
with gr.Row():
|
|
@@ -301,12 +677,21 @@ def create_app():
|
|
| 301 |
gr.Markdown("### Step 3: Deployment Complete")
|
| 302 |
|
| 303 |
with gr.Row():
|
| 304 |
-
with gr.Column():
|
|
|
|
| 305 |
full_package_download = gr.File(
|
| 306 |
-
label="
|
| 307 |
file_types=[".zip"],
|
| 308 |
interactive=False
|
| 309 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
deployment_status = gr.Markdown()
|
| 312 |
|
|
@@ -316,11 +701,40 @@ def create_app():
|
|
| 316 |
|
| 317 |
# Status output
|
| 318 |
status_output = gr.HTML(
|
| 319 |
-
value='
|
| 320 |
elem_id="status_output"
|
| 321 |
)
|
| 322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
convert_btn.click(
|
| 325 |
fn=app.process_step1,
|
| 326 |
inputs=[text_input, file_input, groq_api_key],
|
|
@@ -336,6 +750,10 @@ def create_app():
|
|
| 336 |
fn=lambda step: (gr.update(visible=step==1), gr.update(visible=step==2), gr.update(visible=step==3)),
|
| 337 |
inputs=[current_step],
|
| 338 |
outputs=[step1_group, step2_group, step3_group]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
)
|
| 340 |
|
| 341 |
deploy_btn.click(
|
|
@@ -346,11 +764,19 @@ def create_app():
|
|
| 346 |
fn=lambda step: (gr.update(visible=step==1), gr.update(visible=step==2), gr.update(visible=step==3)),
|
| 347 |
inputs=[current_step],
|
| 348 |
outputs=[step1_group, step2_group, step3_group]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
)
|
| 350 |
|
| 351 |
back_btn_step2.click(
|
| 352 |
fn=lambda: (1, gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)),
|
| 353 |
outputs=[current_step, step1_group, step2_group, step3_group]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
)
|
| 355 |
|
| 356 |
back_btn_step3.click(
|
|
@@ -360,6 +786,10 @@ def create_app():
|
|
| 360 |
fn=app.cleanup,
|
| 361 |
inputs=None,
|
| 362 |
outputs=None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
)
|
| 364 |
|
| 365 |
finish_btn.click(
|
|
|
|
| 146 |
def _create_status_message(self, msg_type, message):
|
| 147 |
"""Create formatted status message"""
|
| 148 |
icons = {
|
| 149 |
+
"success": "✓",
|
| 150 |
+
"error": "✗",
|
| 151 |
+
"warning": "⚠",
|
| 152 |
+
"info": "ℹ"
|
| 153 |
}
|
| 154 |
colors = {
|
| 155 |
"success": "#10B981",
|
|
|
|
| 160 |
|
| 161 |
return f'''
|
| 162 |
<div class="status-message {msg_type}">
|
| 163 |
+
<span style="font-weight: bold; color: {colors[msg_type]}; margin-right: 8px;">
|
| 164 |
{icons[msg_type]}
|
| 165 |
</span>
|
| 166 |
+
<span>{message}</span>
|
| 167 |
</div>
|
| 168 |
'''
|
| 169 |
|
|
|
|
| 172 |
"""Create the Gradio application interface"""
|
| 173 |
app = SpaceCreatorApp()
|
| 174 |
|
| 175 |
+
# Use a clean, professional theme
|
| 176 |
theme = gr.themes.Base(
|
| 177 |
primary_hue="blue",
|
| 178 |
secondary_hue="gray",
|
| 179 |
neutral_hue="gray",
|
| 180 |
+
font=("Inter", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif")
|
| 181 |
)
|
| 182 |
|
| 183 |
with gr.Blocks(
|
| 184 |
title="Hugging Face Space Creator",
|
| 185 |
theme=theme,
|
| 186 |
+
css="""
|
| 187 |
+
/* Simple, clean CSS */
|
| 188 |
+
.gradio-container {
|
| 189 |
+
max-width: 1200px !important;
|
| 190 |
+
margin: 20px auto !important;
|
| 191 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
body {
|
| 195 |
+
background: #f8fafc;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/* Header */
|
| 199 |
+
.header {
|
| 200 |
+
background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
|
| 201 |
+
color: white;
|
| 202 |
+
padding: 2rem;
|
| 203 |
+
border-radius: 8px 8px 0 0;
|
| 204 |
+
margin-bottom: 20px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.header h1 {
|
| 208 |
+
margin: 0;
|
| 209 |
+
font-size: 1.875rem;
|
| 210 |
+
font-weight: 600;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.header p {
|
| 214 |
+
margin: 0.5rem 0 0 0;
|
| 215 |
+
color: #cbd5e1;
|
| 216 |
+
font-size: 1rem;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/* Layout */
|
| 220 |
+
.main-layout {
|
| 221 |
+
display: flex;
|
| 222 |
+
gap: 20px;
|
| 223 |
+
margin-top: 20px;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
.sidebar {
|
| 227 |
+
flex: 1;
|
| 228 |
+
background: white;
|
| 229 |
+
padding: 1.5rem;
|
| 230 |
+
border-radius: 8px;
|
| 231 |
+
border: 1px solid #e2e8f0;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
.content {
|
| 235 |
+
flex: 3;
|
| 236 |
+
background: white;
|
| 237 |
+
padding: 1.5rem;
|
| 238 |
+
border-radius: 8px;
|
| 239 |
+
border: 1px solid #e2e8f0;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
/* Steps */
|
| 243 |
+
.step {
|
| 244 |
+
padding: 1rem;
|
| 245 |
+
margin-bottom: 0.75rem;
|
| 246 |
+
background: #f8fafc;
|
| 247 |
+
border-radius: 6px;
|
| 248 |
+
border: 1px solid #e2e8f0;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.step.active {
|
| 252 |
+
background: #eff6ff;
|
| 253 |
+
border-color: #3b82f6;
|
| 254 |
+
border-left: 4px solid #3b82f6;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
.step-number {
|
| 258 |
+
display: inline-block;
|
| 259 |
+
width: 24px;
|
| 260 |
+
height: 24px;
|
| 261 |
+
background: #cbd5e1;
|
| 262 |
+
color: #475569;
|
| 263 |
+
border-radius: 50%;
|
| 264 |
+
text-align: center;
|
| 265 |
+
line-height: 24px;
|
| 266 |
+
font-size: 0.875rem;
|
| 267 |
+
font-weight: 500;
|
| 268 |
+
margin-right: 0.75rem;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.step.active .step-number {
|
| 272 |
+
background: #3b82f6;
|
| 273 |
+
color: white;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
.step-title {
|
| 277 |
+
font-weight: 600;
|
| 278 |
+
color: #1e293b;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.step-description {
|
| 282 |
+
font-size: 0.875rem;
|
| 283 |
+
color: #64748b;
|
| 284 |
+
margin-top: 0.25rem;
|
| 285 |
+
margin-left: 2.5rem;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/* Form Elements */
|
| 289 |
+
.form-group {
|
| 290 |
+
margin-bottom: 1.5rem;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
input, textarea, select {
|
| 294 |
+
width: 100%;
|
| 295 |
+
padding: 0.75rem 1rem;
|
| 296 |
+
border: 1px solid #cbd5e1;
|
| 297 |
+
border-radius: 6px;
|
| 298 |
+
font-size: 0.875rem;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
input:focus, textarea:focus, select:focus {
|
| 302 |
+
outline: none;
|
| 303 |
+
border-color: #3b82f6;
|
| 304 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/* Buttons */
|
| 308 |
+
button {
|
| 309 |
+
padding: 0.75rem 1.5rem !important;
|
| 310 |
+
border-radius: 6px !important;
|
| 311 |
+
font-weight: 500 !important;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
button.primary {
|
| 315 |
+
background: #3b82f6 !important;
|
| 316 |
+
color: white !important;
|
| 317 |
+
border: none !important;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
button.primary:hover {
|
| 321 |
+
background: #2563eb !important;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
button.secondary {
|
| 325 |
+
background: white !important;
|
| 326 |
+
color: #475569 !important;
|
| 327 |
+
border: 1px solid #cbd5e1 !important;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
button.secondary:hover {
|
| 331 |
+
background: #f8fafc !important;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/* Tabs */
|
| 335 |
+
.tab-nav button {
|
| 336 |
+
padding: 0.75rem 1.5rem !important;
|
| 337 |
+
background: none !important;
|
| 338 |
+
border: none !important;
|
| 339 |
+
border-bottom: 2px solid transparent !important;
|
| 340 |
+
color: #64748b !important;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
.tab-nav button.selected {
|
| 344 |
+
color: #3b82f6 !important;
|
| 345 |
+
border-bottom-color: #3b82f6 !important;
|
| 346 |
+
font-weight: 600 !important;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/* Code Editor */
|
| 350 |
+
#code_editor {
|
| 351 |
+
font-family: 'JetBrains Mono', 'Consolas', monospace !important;
|
| 352 |
+
font-size: 0.875rem !important;
|
| 353 |
+
background: #f8fafc !important;
|
| 354 |
+
border: 1px solid #e2e8f0 !important;
|
| 355 |
+
border-radius: 6px !important;
|
| 356 |
+
padding: 1rem !important;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
/* Status Messages */
|
| 360 |
+
.status-message {
|
| 361 |
+
padding: 1rem;
|
| 362 |
+
border-radius: 6px;
|
| 363 |
+
margin: 1rem 0;
|
| 364 |
+
border-left: 4px solid;
|
| 365 |
+
background: #f8fafc;
|
| 366 |
+
font-size: 0.875rem;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
.status-message.success {
|
| 370 |
+
border-left-color: #10b981;
|
| 371 |
+
background: #f0fdf4;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
.status-message.error {
|
| 375 |
+
border-left-color: #ef4444;
|
| 376 |
+
background: #fef2f2;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
.status-message.warning {
|
| 380 |
+
border-left-color: #f59e0b;
|
| 381 |
+
background: #fffbeb;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
.status-message.info {
|
| 385 |
+
border-left-color: #3b82f6;
|
| 386 |
+
background: #eff6ff;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/* File Cards */
|
| 390 |
+
.file-card {
|
| 391 |
+
border: 1px solid #e2e8f0;
|
| 392 |
+
border-radius: 6px;
|
| 393 |
+
padding: 1rem;
|
| 394 |
+
margin-bottom: 1rem;
|
| 395 |
+
background: #f8fafc;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
.file-card-title {
|
| 399 |
+
font-weight: 600;
|
| 400 |
+
color: #1e293b;
|
| 401 |
+
margin-bottom: 0.5rem;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
/* Error Message */
|
| 405 |
+
.error-message {
|
| 406 |
+
background: #fef2f2;
|
| 407 |
+
border: 1px solid #fecaca;
|
| 408 |
+
border-radius: 6px;
|
| 409 |
+
padding: 1rem;
|
| 410 |
+
margin: 1rem 0;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
.error-message h4 {
|
| 414 |
+
margin: 0 0 0.5rem 0;
|
| 415 |
+
color: #dc2626;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
.error-message ul {
|
| 419 |
+
margin: 0;
|
| 420 |
+
padding-left: 1.25rem;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
.error-message li {
|
| 424 |
+
margin-bottom: 0.25rem;
|
| 425 |
+
color: #57534e;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
/* Progress Bar */
|
| 429 |
+
.progress-bar {
|
| 430 |
+
height: 4px;
|
| 431 |
+
background: #e2e8f0;
|
| 432 |
+
border-radius: 2px;
|
| 433 |
+
margin: 1rem 0;
|
| 434 |
+
overflow: hidden;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
.progress-fill {
|
| 438 |
+
height: 100%;
|
| 439 |
+
background: #3b82f6;
|
| 440 |
+
width: 33.33%;
|
| 441 |
+
transition: width 0.3s ease;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
.progress-fill.step2 { width: 66.66%; }
|
| 445 |
+
.progress-fill.step3 { width: 100%; }
|
| 446 |
+
|
| 447 |
+
/* Tips Box */
|
| 448 |
+
.tips-box {
|
| 449 |
+
background: #eff6ff;
|
| 450 |
+
border: 1px solid #bfdbfe;
|
| 451 |
+
border-radius: 6px;
|
| 452 |
+
padding: 1rem;
|
| 453 |
+
margin-top: 1.5rem;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
.tips-box h4 {
|
| 457 |
+
margin: 0 0 0.75rem 0;
|
| 458 |
+
color: #1e40af;
|
| 459 |
+
font-size: 0.875rem;
|
| 460 |
+
font-weight: 600;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
.tip {
|
| 464 |
+
display: flex;
|
| 465 |
+
align-items: flex-start;
|
| 466 |
+
gap: 0.75rem;
|
| 467 |
+
margin-bottom: 0.75rem;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
.tip:last-child {
|
| 471 |
+
margin-bottom: 0;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
.tip-icon {
|
| 475 |
+
color: #3b82f6;
|
| 476 |
+
flex-shrink: 0;
|
| 477 |
+
margin-top: 0.125rem;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
.tip-text {
|
| 481 |
+
font-size: 0.875rem;
|
| 482 |
+
color: #374151;
|
| 483 |
+
line-height: 1.5;
|
| 484 |
+
}
|
| 485 |
+
"""
|
| 486 |
) as demo:
|
| 487 |
|
| 488 |
+
# Add font
|
| 489 |
+
gr.HTML('<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">')
|
| 490 |
|
| 491 |
+
# Simple Header
|
| 492 |
+
header_html = '''
|
| 493 |
+
<div class="header">
|
| 494 |
+
<h1>Space Creator</h1>
|
| 495 |
+
<p>Convert Python code to deployable Gradio applications</p>
|
| 496 |
+
</div>
|
| 497 |
+
'''
|
| 498 |
+
gr.HTML(header_html)
|
| 499 |
|
| 500 |
+
# Progress Bar
|
| 501 |
+
progress_html = '''
|
| 502 |
+
<div class="progress-bar">
|
| 503 |
+
<div class="progress-fill" id="progress-fill"></div>
|
| 504 |
+
</div>
|
| 505 |
+
'''
|
| 506 |
+
gr.HTML(progress_html)
|
| 507 |
+
|
| 508 |
+
with gr.Row(elem_classes="main-layout"):
|
| 509 |
+
# Sidebar
|
| 510 |
+
with gr.Column(scale=1, min_width=280, elem_classes="sidebar"):
|
| 511 |
current_step = gr.State(1)
|
| 512 |
+
|
| 513 |
+
# Steps
|
| 514 |
+
steps_html = '''
|
| 515 |
+
<div style="margin-bottom: 1.5rem;">
|
| 516 |
+
<h3 style="margin: 0 0 1rem 0; font-size: 1rem; font-weight: 600; color: #1e293b;">
|
| 517 |
+
Workflow Steps
|
| 518 |
+
</h3>
|
| 519 |
+
<div class="step active">
|
| 520 |
+
<span class="step-number">1</span>
|
| 521 |
+
<span class="step-title">Input Code</span>
|
| 522 |
+
<div class="step-description">Provide your Python code</div>
|
| 523 |
+
</div>
|
| 524 |
+
<div class="step">
|
| 525 |
+
<span class="step-number">2</span>
|
| 526 |
+
<span class="step-title">Generate Files</span>
|
| 527 |
+
<div class="step-description">Create Gradio app files</div>
|
| 528 |
+
</div>
|
| 529 |
+
<div class="step">
|
| 530 |
+
<span class="step-number">3</span>
|
| 531 |
+
<span class="step-title">Deploy</span>
|
| 532 |
+
<div class="step-description">Deploy to Hugging Face</div>
|
| 533 |
+
</div>
|
| 534 |
+
</div>
|
| 535 |
+
'''
|
| 536 |
+
gr.HTML(steps_html)
|
| 537 |
+
|
| 538 |
+
# Tips
|
| 539 |
+
tips_html = '''
|
| 540 |
+
<div class="tips-box">
|
| 541 |
+
<h4>Quick Tips</h4>
|
| 542 |
+
<div class="tip">
|
| 543 |
+
<div class="tip-icon">•</div>
|
| 544 |
+
<div class="tip-text">Ensure your code is well-structured for best results</div>
|
| 545 |
+
</div>
|
| 546 |
+
<div class="tip">
|
| 547 |
+
<div class="tip-icon">•</div>
|
| 548 |
+
<div class="tip-text">API keys are used securely and not stored</div>
|
| 549 |
+
</div>
|
| 550 |
+
<div class="tip">
|
| 551 |
+
<div class="tip-icon">•</div>
|
| 552 |
+
<div class="tip-text">One-click deployment to Hugging Face Spaces</div>
|
| 553 |
+
</div>
|
| 554 |
+
</div>
|
| 555 |
+
'''
|
| 556 |
+
gr.HTML(tips_html)
|
| 557 |
|
| 558 |
+
# Main Content
|
| 559 |
+
with gr.Column(scale=3, elem_classes="content"):
|
| 560 |
+
# Step 1: Code Input
|
| 561 |
with gr.Group(visible=True) as step1_group:
|
| 562 |
gr.Markdown("### Step 1: Provide Your Code")
|
| 563 |
|
| 564 |
with gr.Tabs():
|
| 565 |
+
with gr.Tab("Upload File"):
|
| 566 |
file_input = gr.File(
|
| 567 |
label="Upload Python or Jupyter Notebook",
|
| 568 |
file_types=SUPPORTED_EXTENSIONS,
|
| 569 |
type="filepath"
|
| 570 |
)
|
| 571 |
|
| 572 |
+
with gr.Tab("Paste Code"):
|
| 573 |
text_input = gr.Textbox(
|
| 574 |
label="Python Code",
|
| 575 |
+
lines=15,
|
| 576 |
+
placeholder="# Paste your Python code here...\n# Example:\ndef add(a, b):\n return a + b",
|
| 577 |
elem_id="code_editor"
|
| 578 |
)
|
| 579 |
|
| 580 |
+
gr.Markdown("### Step 2: API Configuration")
|
| 581 |
+
groq_api_key = gr.Textbox(
|
| 582 |
+
label="Groq API Key",
|
| 583 |
+
type="password",
|
| 584 |
+
placeholder="Enter your Groq API key (starts with gsk_)",
|
| 585 |
+
info="Required for AI-powered conversion"
|
| 586 |
+
)
|
|
|
|
|
|
|
| 587 |
|
| 588 |
+
# API Guide
|
| 589 |
+
with gr.Accordion("Need help creating API keys?", open=False):
|
| 590 |
+
with gr.Tabs():
|
| 591 |
+
with gr.Tab("Groq API Key"):
|
| 592 |
+
gr.Markdown("""
|
| 593 |
+
1. Go to [Groq Console](https://console.groq.com)
|
| 594 |
+
2. Sign up or log in
|
| 595 |
+
3. Navigate to **API Keys** section
|
| 596 |
+
4. Click **Create API Key**
|
| 597 |
+
5. Copy the key (starts with `gsk_`)
|
| 598 |
+
6. Paste it in the field above
|
| 599 |
+
""")
|
| 600 |
+
|
| 601 |
+
with gr.Tab("Hugging Face Token"):
|
| 602 |
+
gr.Markdown("""
|
| 603 |
+
1. Go to [Hugging Face](https://huggingface.co)
|
| 604 |
+
2. Click profile → **Settings**
|
| 605 |
+
3. Navigate to **Access Tokens**
|
| 606 |
+
4. Click **New Token**
|
| 607 |
+
5. Select token type: **Write**
|
| 608 |
+
6. Copy the token (starts with `hf_`)
|
| 609 |
+
7. Paste it in Step 2
|
| 610 |
+
""")
|
| 611 |
|
| 612 |
+
convert_btn = gr.Button(
|
| 613 |
+
"Convert Code",
|
| 614 |
+
variant="primary",
|
| 615 |
+
size="lg"
|
| 616 |
+
)
|
|
|
|
|
|
|
| 617 |
|
| 618 |
# Step 2: Generated Files
|
| 619 |
with gr.Group(visible=False) as step2_group:
|
|
|
|
| 621 |
|
| 622 |
with gr.Row():
|
| 623 |
with gr.Column():
|
| 624 |
+
gr.Markdown("**app.py**")
|
| 625 |
app_py_download = gr.File(
|
| 626 |
+
label="Download app.py",
|
| 627 |
file_types=[".py"],
|
| 628 |
interactive=False
|
| 629 |
)
|
| 630 |
|
| 631 |
with gr.Column():
|
| 632 |
+
gr.Markdown("**requirements.txt**")
|
| 633 |
requirements_download = gr.File(
|
| 634 |
+
label="Download requirements.txt",
|
| 635 |
file_types=[".txt"],
|
| 636 |
interactive=False
|
| 637 |
)
|
| 638 |
|
| 639 |
with gr.Column():
|
| 640 |
+
gr.Markdown("**README.md**")
|
| 641 |
readme_download = gr.File(
|
| 642 |
+
label="Download README.md",
|
| 643 |
file_types=[".md"],
|
| 644 |
interactive=False
|
| 645 |
)
|
| 646 |
|
| 647 |
+
gr.Markdown("### Step 3: Deployment Options")
|
| 648 |
|
| 649 |
with gr.Row():
|
| 650 |
with gr.Column():
|
| 651 |
hf_token = gr.Textbox(
|
| 652 |
label="Hugging Face Token",
|
| 653 |
type="password",
|
| 654 |
+
placeholder="Enter your Hugging Face token (starts with hf_)",
|
| 655 |
info="Required for deployment"
|
| 656 |
)
|
| 657 |
|
| 658 |
with gr.Column():
|
| 659 |
space_name = gr.Textbox(
|
| 660 |
label="Space Name",
|
| 661 |
+
placeholder="my-gradio-app",
|
| 662 |
info="Lowercase letters, numbers, and hyphens only"
|
| 663 |
)
|
| 664 |
|
| 665 |
deploy_mode = gr.Radio(
|
| 666 |
choices=["Download Only", "Deploy to Hugging Face Space"],
|
| 667 |
label="Select Action",
|
| 668 |
+
value="Download Only"
|
|
|
|
| 669 |
)
|
| 670 |
|
| 671 |
with gr.Row():
|
|
|
|
| 677 |
gr.Markdown("### Step 3: Deployment Complete")
|
| 678 |
|
| 679 |
with gr.Row():
|
| 680 |
+
with gr.Column(scale=2):
|
| 681 |
+
gr.Markdown("**Complete Application Package**")
|
| 682 |
full_package_download = gr.File(
|
| 683 |
+
label="Download full package",
|
| 684 |
file_types=[".zip"],
|
| 685 |
interactive=False
|
| 686 |
)
|
| 687 |
+
with gr.Column(scale=1):
|
| 688 |
+
gr.Markdown("**Next Steps**")
|
| 689 |
+
gr.Markdown("""
|
| 690 |
+
1. Your app is now deployed
|
| 691 |
+
2. Visit your Hugging Face Space
|
| 692 |
+
3. Monitor deployment logs
|
| 693 |
+
4. Share your app with others
|
| 694 |
+
""")
|
| 695 |
|
| 696 |
deployment_status = gr.Markdown()
|
| 697 |
|
|
|
|
| 701 |
|
| 702 |
# Status output
|
| 703 |
status_output = gr.HTML(
|
| 704 |
+
value='',
|
| 705 |
elem_id="status_output"
|
| 706 |
)
|
| 707 |
|
| 708 |
+
# JavaScript for updating progress bar
|
| 709 |
+
js_code = """
|
| 710 |
+
<script>
|
| 711 |
+
function updateProgress(step) {
|
| 712 |
+
const progressFill = document.getElementById('progress-fill');
|
| 713 |
+
progressFill.className = 'progress-fill';
|
| 714 |
+
if (step === 2) progressFill.classList.add('step2');
|
| 715 |
+
if (step === 3) progressFill.classList.add('step3');
|
| 716 |
+
|
| 717 |
+
// Update steps in sidebar
|
| 718 |
+
const steps = document.querySelectorAll('.step');
|
| 719 |
+
steps.forEach((stepEl, index) => {
|
| 720 |
+
stepEl.classList.remove('active');
|
| 721 |
+
if (index + 1 === step) {
|
| 722 |
+
stepEl.classList.add('active');
|
| 723 |
+
}
|
| 724 |
+
});
|
| 725 |
+
}
|
| 726 |
+
</script>
|
| 727 |
+
"""
|
| 728 |
+
gr.HTML(js_code)
|
| 729 |
+
|
| 730 |
# Event handlers
|
| 731 |
+
def update_progress_bar(step):
|
| 732 |
+
return f"""
|
| 733 |
+
<script>
|
| 734 |
+
updateProgress({step});
|
| 735 |
+
</script>
|
| 736 |
+
"""
|
| 737 |
+
|
| 738 |
convert_btn.click(
|
| 739 |
fn=app.process_step1,
|
| 740 |
inputs=[text_input, file_input, groq_api_key],
|
|
|
|
| 750 |
fn=lambda step: (gr.update(visible=step==1), gr.update(visible=step==2), gr.update(visible=step==3)),
|
| 751 |
inputs=[current_step],
|
| 752 |
outputs=[step1_group, step2_group, step3_group]
|
| 753 |
+
).then(
|
| 754 |
+
fn=update_progress_bar,
|
| 755 |
+
inputs=[current_step],
|
| 756 |
+
outputs=[status_output]
|
| 757 |
)
|
| 758 |
|
| 759 |
deploy_btn.click(
|
|
|
|
| 764 |
fn=lambda step: (gr.update(visible=step==1), gr.update(visible=step==2), gr.update(visible=step==3)),
|
| 765 |
inputs=[current_step],
|
| 766 |
outputs=[step1_group, step2_group, step3_group]
|
| 767 |
+
).then(
|
| 768 |
+
fn=update_progress_bar,
|
| 769 |
+
inputs=[current_step],
|
| 770 |
+
outputs=[status_output]
|
| 771 |
)
|
| 772 |
|
| 773 |
back_btn_step2.click(
|
| 774 |
fn=lambda: (1, gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)),
|
| 775 |
outputs=[current_step, step1_group, step2_group, step3_group]
|
| 776 |
+
).then(
|
| 777 |
+
fn=update_progress_bar,
|
| 778 |
+
inputs=[current_step],
|
| 779 |
+
outputs=[status_output]
|
| 780 |
)
|
| 781 |
|
| 782 |
back_btn_step3.click(
|
|
|
|
| 786 |
fn=app.cleanup,
|
| 787 |
inputs=None,
|
| 788 |
outputs=None
|
| 789 |
+
).then(
|
| 790 |
+
fn=update_progress_bar,
|
| 791 |
+
inputs=[current_step],
|
| 792 |
+
outputs=[status_output]
|
| 793 |
)
|
| 794 |
|
| 795 |
finish_btn.click(
|