akhaliq HF Staff commited on
Commit
d35fab9
·
1 Parent(s): b73d5d9

update to add login

Browse files
Files changed (1) hide show
  1. app.py +51 -41
app.py CHANGED
@@ -1056,62 +1056,53 @@ with gr.Blocks(
1056
  })
1057
  current_model = gr.State(AVAILABLE_MODELS[1]) # DeepSeek V3
1058
  open_panel = gr.State(None)
 
1059
 
1060
  with gr.Sidebar():
1061
- gr.Markdown("# AnyCoder")
1062
- gr.Markdown("*AI-Powered Code Generator*")
1063
-
1064
- gr.Markdown("---") # Separator
1065
-
1066
- # Main input section
 
1067
  input = gr.Textbox(
1068
  label="What would you like to build?",
1069
  placeholder="Describe your application...",
1070
- lines=3
 
1071
  )
1072
-
1073
- # URL input for website redesign
1074
  website_url_input = gr.Textbox(
1075
  label="Website URL for redesign",
1076
  placeholder="https://example.com",
1077
  lines=1,
1078
- visible=True
1079
  )
1080
-
1081
- # File upload (minimal)
1082
  file_input = gr.File(
1083
  label="Reference file",
1084
  file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],
1085
- visible=True
1086
  )
1087
-
1088
- # Image input (only for ERNIE model)
1089
  image_input = gr.Image(
1090
  label="UI design image",
1091
  visible=False
1092
  )
1093
-
1094
- # Action buttons
1095
  with gr.Row():
1096
- btn = gr.Button("Generate", variant="primary", size="lg", scale=2)
1097
- clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1)
1098
-
1099
- # Search toggle (minimal)
1100
  search_toggle = gr.Checkbox(
1101
  label="🔍 Web search",
1102
- value=False
 
1103
  )
1104
-
1105
- # Model selection (minimal)
1106
  model_dropdown = gr.Dropdown(
1107
  choices=[model['name'] for model in AVAILABLE_MODELS],
1108
  value=AVAILABLE_MODELS[1]['name'], # DeepSeek V3
1109
- label="Model"
 
1110
  )
1111
-
1112
- # Quick examples (minimal)
1113
- gr.Markdown("**Quick start**")
1114
- with gr.Column():
1115
  for i, demo_item in enumerate(DEMO_LIST[:3]):
1116
  demo_card = gr.Button(
1117
  value=demo_item['title'],
@@ -1122,33 +1113,24 @@ with gr.Blocks(
1122
  fn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),
1123
  outputs=input
1124
  )
1125
-
1126
- # Status indicators (minimal)
1127
  if not tavily_client:
1128
- gr.Markdown("⚠️ Web search unavailable")
1129
  else:
1130
- gr.Markdown("✅ Web search available")
1131
-
1132
- # Hidden elements for functionality
1133
  model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[1]['name']}", visible=False) # DeepSeek V3
1134
-
1135
  def on_model_change(model_name):
1136
  for m in AVAILABLE_MODELS:
1137
  if m['name'] == model_name:
1138
  return m, f"**Model:** {m['name']}", update_image_input_visibility(m)
1139
  return AVAILABLE_MODELS[1], f"**Model:** {AVAILABLE_MODELS[1]['name']}", update_image_input_visibility(AVAILABLE_MODELS[1]) # DeepSeek V3 fallback
1140
-
1141
  def save_prompt(input):
1142
  return {setting: {"system": input}}
1143
-
1144
  model_dropdown.change(
1145
  on_model_change,
1146
  inputs=model_dropdown,
1147
  outputs=[current_model, model_display, image_input]
1148
  )
1149
-
1150
- # System prompt (collapsed by default)
1151
- with gr.Accordion("Advanced", open=False):
1152
  systemPromptInput = gr.Textbox(
1153
  value=SystemPrompt,
1154
  label="System prompt",
@@ -1157,6 +1139,34 @@ with gr.Blocks(
1157
  save_prompt_btn = gr.Button("Save", variant="primary", size="sm")
1158
  save_prompt_btn.click(save_prompt, inputs=systemPromptInput, outputs=setting)
1159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1160
  with gr.Column():
1161
  with gr.Tabs():
1162
  with gr.Tab("Code"):
 
1056
  })
1057
  current_model = gr.State(AVAILABLE_MODELS[1]) # DeepSeek V3
1058
  open_panel = gr.State(None)
1059
+ last_login_state = gr.State(None)
1060
 
1061
  with gr.Sidebar():
1062
+ # Add Hugging Face Login Button at the top of the sidebar
1063
+ login_button = gr.LoginButton(
1064
+ value="Sign in with Hugging Face",
1065
+ variant="huggingface",
1066
+ size="lg"
1067
+ )
1068
+ login_required_msg = gr.Markdown("**Please sign in with Hugging Face to use the app.**", visible=True)
1069
  input = gr.Textbox(
1070
  label="What would you like to build?",
1071
  placeholder="Describe your application...",
1072
+ lines=3,
1073
+ visible=False
1074
  )
 
 
1075
  website_url_input = gr.Textbox(
1076
  label="Website URL for redesign",
1077
  placeholder="https://example.com",
1078
  lines=1,
1079
+ visible=False
1080
  )
 
 
1081
  file_input = gr.File(
1082
  label="Reference file",
1083
  file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],
1084
+ visible=False
1085
  )
 
 
1086
  image_input = gr.Image(
1087
  label="UI design image",
1088
  visible=False
1089
  )
 
 
1090
  with gr.Row():
1091
+ btn = gr.Button("Generate", variant="primary", size="lg", scale=2, visible=False)
1092
+ clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=False)
 
 
1093
  search_toggle = gr.Checkbox(
1094
  label="🔍 Web search",
1095
+ value=False,
1096
+ visible=False
1097
  )
 
 
1098
  model_dropdown = gr.Dropdown(
1099
  choices=[model['name'] for model in AVAILABLE_MODELS],
1100
  value=AVAILABLE_MODELS[1]['name'], # DeepSeek V3
1101
+ label="Model",
1102
+ visible=False
1103
  )
1104
+ gr.Markdown("**Quick start**", visible=False)
1105
+ with gr.Column(visible=False) as quick_examples_col:
 
 
1106
  for i, demo_item in enumerate(DEMO_LIST[:3]):
1107
  demo_card = gr.Button(
1108
  value=demo_item['title'],
 
1113
  fn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),
1114
  outputs=input
1115
  )
 
 
1116
  if not tavily_client:
1117
+ gr.Markdown("⚠️ Web search unavailable", visible=False)
1118
  else:
1119
+ gr.Markdown("✅ Web search available", visible=False)
 
 
1120
  model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[1]['name']}", visible=False) # DeepSeek V3
 
1121
  def on_model_change(model_name):
1122
  for m in AVAILABLE_MODELS:
1123
  if m['name'] == model_name:
1124
  return m, f"**Model:** {m['name']}", update_image_input_visibility(m)
1125
  return AVAILABLE_MODELS[1], f"**Model:** {AVAILABLE_MODELS[1]['name']}", update_image_input_visibility(AVAILABLE_MODELS[1]) # DeepSeek V3 fallback
 
1126
  def save_prompt(input):
1127
  return {setting: {"system": input}}
 
1128
  model_dropdown.change(
1129
  on_model_change,
1130
  inputs=model_dropdown,
1131
  outputs=[current_model, model_display, image_input]
1132
  )
1133
+ with gr.Accordion("Advanced", open=False, visible=False) as advanced_accordion:
 
 
1134
  systemPromptInput = gr.Textbox(
1135
  value=SystemPrompt,
1136
  label="System prompt",
 
1139
  save_prompt_btn = gr.Button("Save", variant="primary", size="sm")
1140
  save_prompt_btn.click(save_prompt, inputs=systemPromptInput, outputs=setting)
1141
 
1142
+ # Timer-based login state polling
1143
+ login_state = gr.State(False)
1144
+ timer = gr.Timer(1, active=True)
1145
+ def check_login(label, last_state):
1146
+ logged_in = label.startswith("Logout (")
1147
+ # Only update if state changes
1148
+ if last_state == logged_in:
1149
+ return [gr.skip()] * 12 # skip updating all outputs
1150
+ return (
1151
+ logged_in, # login_state
1152
+ gr.update(visible=not logged_in), # login_required_msg
1153
+ gr.update(visible=logged_in), # input
1154
+ gr.update(visible=logged_in), # website_url_input
1155
+ gr.update(visible=logged_in), # file_input
1156
+ gr.update(visible=logged_in), # btn
1157
+ gr.update(visible=logged_in), # clear_btn
1158
+ gr.update(visible=logged_in), # search_toggle
1159
+ gr.update(visible=logged_in), # model_dropdown
1160
+ gr.update(visible=logged_in), # quick_examples_col
1161
+ gr.update(visible=logged_in), # advanced_accordion
1162
+ logged_in, # update last_login_state
1163
+ )
1164
+ timer.tick(
1165
+ fn=check_login,
1166
+ inputs=[login_button, last_login_state],
1167
+ outputs=[login_state, login_required_msg, input, website_url_input, file_input, btn, clear_btn, search_toggle, model_dropdown, quick_examples_col, advanced_accordion, last_login_state]
1168
+ )
1169
+
1170
  with gr.Column():
1171
  with gr.Tabs():
1172
  with gr.Tab("Code"):