akhaliq HF Staff commited on
Commit
5644d41
Β·
1 Parent(s): bbf54e8

move deploy and hide until after app is generated

Browse files
Files changed (1) hide show
  1. app.py +45 -34
app.py CHANGED
@@ -1178,31 +1178,11 @@ with gr.Blocks(
1178
 
1179
  with gr.Sidebar():
1180
  login_button = gr.LoginButton()
1181
- space_name_input = gr.Textbox(
1182
- label="app name (e.g. my-cool-app)",
1183
- placeholder="Enter your app name",
1184
- lines=1,
1185
- visible=True
1186
- )
1187
- # Add SDK selection dropdown
1188
- sdk_choices = [
1189
- ("Gradio (Python)", "gradio"),
1190
- ("Streamlit (Python)", "streamlit"),
1191
- ("Static (HTML)", "static")
1192
- ]
1193
- sdk_dropdown = gr.Dropdown(
1194
- choices=[x[0] for x in sdk_choices],
1195
- value="Static (HTML)",
1196
- label="App SDK",
1197
- visible=True
1198
- )
1199
- deploy_btn = gr.Button("πŸš€ Deploy App", variant="primary")
1200
- deploy_status = gr.Markdown(visible=False, label="Deploy status")
1201
  input = gr.Textbox(
1202
  label="What would you like to build?",
1203
  placeholder="Describe your application...",
1204
  lines=3,
1205
- visible=True # Always visible
1206
  )
1207
  # Language dropdown for code generation
1208
  language_choices = [
@@ -1212,36 +1192,57 @@ with gr.Blocks(
1212
  choices=language_choices,
1213
  value="html",
1214
  label="Code Language",
1215
- visible=True # Always visible
1216
  )
1217
  website_url_input = gr.Textbox(
1218
  label="website for redesign",
1219
  placeholder="https://example.com",
1220
  lines=1,
1221
- visible=True # Always visible
1222
  )
1223
  file_input = gr.File(
1224
  label="Reference file",
1225
  file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],
1226
- visible=True # Always visible
1227
  )
1228
  image_input = gr.Image(
1229
  label="UI design image",
1230
- visible=False # Hidden by default; shown only for ERNIE-VL or GLM-VL
1231
  )
1232
  with gr.Row():
1233
- btn = gr.Button("Generate", variant="primary", size="lg", scale=2, visible=True) # Always visible
1234
- clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=True) # Always visible
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1235
  search_toggle = gr.Checkbox(
1236
  label="πŸ” Web search",
1237
  value=False,
1238
- visible=True # Always visible
1239
  )
1240
  model_dropdown = gr.Dropdown(
1241
  choices=[model['name'] for model in AVAILABLE_MODELS],
1242
- value=AVAILABLE_MODELS[0]['name'], # Moonshot Kimi-K2
1243
  label="Model",
1244
- visible=True # Always visible
1245
  )
1246
  provider_state = gr.State("auto")
1247
  gr.Markdown("**Quick start**", visible=True)
@@ -1263,7 +1264,7 @@ with gr.Blocks(
1263
  for m in AVAILABLE_MODELS:
1264
  if m['name'] == model_name:
1265
  return m, update_image_input_visibility(m)
1266
- return AVAILABLE_MODELS[0], update_image_input_visibility(AVAILABLE_MODELS[0]) # Moonshot Kimi-K2 fallback
1267
  def save_prompt(input):
1268
  return {setting: {"system": input}}
1269
  model_dropdown.change(
@@ -1271,9 +1272,8 @@ with gr.Blocks(
1271
  inputs=model_dropdown,
1272
  outputs=[current_model, image_input]
1273
  )
1274
- # Remove the Advanced accordion and system prompt editing UI
1275
- # login_button.render()
1276
- # space_name_input.render()
1277
 
1278
  with gr.Column():
1279
  with gr.Tabs():
@@ -1301,15 +1301,26 @@ with gr.Blocks(
1301
  else:
1302
  return "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your code using the download button above.</div>"
1303
 
 
 
 
 
 
 
1304
  btn.click(
1305
  generation_code,
1306
  inputs=[input, image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state],
1307
  outputs=[code_output, history, sandbox, history_output]
 
 
 
 
1308
  )
1309
  # Update preview when code or language changes
1310
  code_output.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
1311
  language_dropdown.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
1312
  clear_btn.click(clear_history, outputs=[history, history_output, file_input, website_url_input])
 
1313
 
1314
  # Deploy to Spaces logic
1315
 
 
1178
 
1179
  with gr.Sidebar():
1180
  login_button = gr.LoginButton()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1181
  input = gr.Textbox(
1182
  label="What would you like to build?",
1183
  placeholder="Describe your application...",
1184
  lines=3,
1185
+ visible=True
1186
  )
1187
  # Language dropdown for code generation
1188
  language_choices = [
 
1192
  choices=language_choices,
1193
  value="html",
1194
  label="Code Language",
1195
+ visible=True
1196
  )
1197
  website_url_input = gr.Textbox(
1198
  label="website for redesign",
1199
  placeholder="https://example.com",
1200
  lines=1,
1201
+ visible=True
1202
  )
1203
  file_input = gr.File(
1204
  label="Reference file",
1205
  file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],
1206
+ visible=True
1207
  )
1208
  image_input = gr.Image(
1209
  label="UI design image",
1210
+ visible=False
1211
  )
1212
  with gr.Row():
1213
+ btn = gr.Button("Generate", variant="primary", size="lg", scale=2, visible=True)
1214
+ clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=True)
1215
+ # --- Move deploy/app name/sdk here, right before web search ---
1216
+ space_name_input = gr.Textbox(
1217
+ label="app name (e.g. my-cool-app)",
1218
+ placeholder="Enter your app name",
1219
+ lines=1,
1220
+ visible=False
1221
+ )
1222
+ sdk_choices = [
1223
+ ("Gradio (Python)", "gradio"),
1224
+ ("Streamlit (Python)", "streamlit"),
1225
+ ("Static (HTML)", "static")
1226
+ ]
1227
+ sdk_dropdown = gr.Dropdown(
1228
+ choices=[x[0] for x in sdk_choices],
1229
+ value="Static (HTML)",
1230
+ label="App SDK",
1231
+ visible=False
1232
+ )
1233
+ deploy_btn = gr.Button("πŸš€ Deploy App", variant="primary", visible=False)
1234
+ deploy_status = gr.Markdown(visible=False, label="Deploy status")
1235
+ # --- End move ---
1236
  search_toggle = gr.Checkbox(
1237
  label="πŸ” Web search",
1238
  value=False,
1239
+ visible=True
1240
  )
1241
  model_dropdown = gr.Dropdown(
1242
  choices=[model['name'] for model in AVAILABLE_MODELS],
1243
+ value=AVAILABLE_MODELS[0]['name'],
1244
  label="Model",
1245
+ visible=True
1246
  )
1247
  provider_state = gr.State("auto")
1248
  gr.Markdown("**Quick start**", visible=True)
 
1264
  for m in AVAILABLE_MODELS:
1265
  if m['name'] == model_name:
1266
  return m, update_image_input_visibility(m)
1267
+ return AVAILABLE_MODELS[0], update_image_input_visibility(AVAILABLE_MODELS[0])
1268
  def save_prompt(input):
1269
  return {setting: {"system": input}}
1270
  model_dropdown.change(
 
1272
  inputs=model_dropdown,
1273
  outputs=[current_model, image_input]
1274
  )
1275
+ # --- Remove deploy/app name/sdk from bottom column ---
1276
+ # (delete the gr.Column() block containing space_name_input, sdk_dropdown, deploy_btn, deploy_status)
 
1277
 
1278
  with gr.Column():
1279
  with gr.Tabs():
 
1301
  else:
1302
  return "<div style='padding:1em;color:#888;text-align:center;'>Preview is only available for HTML. Please download your code using the download button above.</div>"
1303
 
1304
+ def show_deploy_components(*args):
1305
+ return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)]
1306
+
1307
+ def hide_deploy_components(*args):
1308
+ return [gr.Textbox(visible=False), gr.Dropdown(visible=False), gr.Button(visible=False)]
1309
+
1310
  btn.click(
1311
  generation_code,
1312
  inputs=[input, image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state],
1313
  outputs=[code_output, history, sandbox, history_output]
1314
+ ).then(
1315
+ show_deploy_components,
1316
+ None,
1317
+ [space_name_input, sdk_dropdown, deploy_btn]
1318
  )
1319
  # Update preview when code or language changes
1320
  code_output.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
1321
  language_dropdown.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
1322
  clear_btn.click(clear_history, outputs=[history, history_output, file_input, website_url_input])
1323
+ clear_btn.click(hide_deploy_components, None, [space_name_input, sdk_dropdown, deploy_btn])
1324
 
1325
  # Deploy to Spaces logic
1326