update to add login
Browse files1055 unmodified lines105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611174 unmodified lines1122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311542 unmodified lines1157115811591160116111621055 unmodified lines})current_model = gr.State(AVAILABLE_MODELS[1]) # DeepSeek V3open_panel = gr.State(None)with gr.Sidebar():gr.Markdown("# AnyCoder")gr.Markdown("*AI-Powered Code Generator*")gr.Markdown("---") # Separator# Main input sectioninput = gr.Textbox(label="What would you like to build?",placeholder="Describe your application...",lines=3)# URL input for website redesignwebsite_url_input = gr.Textbox(label="Website URL for redesign",placeholder="https://example.com",lines=1,visible=True)# File upload (minimal)file_input = gr.File(label="Reference file",file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],visible=True)# Image input (only for ERNIE model)image_input = gr.Image(label="UI design image",visible=False)# Action buttonswith gr.Row():btn = gr.Button("Generate", variant="primary", size="lg", scale=2)clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1)# Search toggle (minimal)search_toggle = gr.Checkbox(label="🔍 Web search",value=False)# Model selection (minimal)model_dropdown = gr.Dropdown(choices=[model['name'] for model in AVAILABLE_MODELS],value=AVAILABLE_MODELS[1]['name'], # DeepSeek V3label="Model")# Quick examples (minimal)gr.Markdown("**Quick start**")with gr.Column():for i, demo_item in enumerate(DEMO_LIST[:3]):demo_card = gr.Button(value=demo_item['title'],4 unmodified linesfn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),outputs=input)# Status indicators (minimal)if not tavily_client:gr.Markdown("⚠️ Web search unavailable")else:gr.Markdown("✅ Web search available")# Hidden elements for functionalitymodel_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[1]['name']}", visible=False) # DeepSeek V3def on_model_change(model_name):for m in AVAILABLE_MODELS:if m['name'] == model_name:return m, f"**Model:** {m['name']}", update_image_input_visibility(m)return AVAILABLE_MODELS[1], f"**Model:** {AVAILABLE_MODELS[1]['name']}", update_image_input_visibility(AVAILABLE_MODELS[1]) # DeepSeek V3 fallbackdef save_prompt(input):return {setting: {"system": input}}model_dropdown.change(on_model_change,inputs=model_dropdown,outputs=[current_model, model_display, image_input])# System prompt (collapsed by default)with gr.Accordion("Advanced", open=False):systemPromptInput = gr.Textbox(value=SystemPrompt,label="System prompt",2 unmodified linessave_prompt_btn = gr.Button("Save", variant="primary", size="sm")save_prompt_btn.click(save_prompt, inputs=systemPromptInput, outputs=setting)with gr.Column():with gr.Tabs():with gr.Tab("Code"):1055 unmodified lines105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711084 unmodified lines1113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511362 unmodified lines11391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721055 unmodified lines})current_model = gr.State(AVAILABLE_MODELS[1]) # DeepSeek V3open_panel = gr.State(None)last_login_state = gr.State(None)with gr.Sidebar():# Add Hugging Face Login Button at the top of the sidebarlogin_button = gr.LoginButton(value="Sign in with Hugging Face",variant="huggingface",size="lg")login_required_msg = gr.Markdown("**Please sign in with Hugging Face to use the app.**", visible=True)input = gr.Textbox(label="What would you like to build?",placeholder="Describe your application...",lines=3,visible=False)website_url_input = gr.Textbox(label="Website URL for redesign",placeholder="https://example.com",lines=1,visible=False)file_input = gr.File(label="Reference file",file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"],visible=False)image_input = gr.Image(label="UI design image",visible=False)with gr.Row():btn = gr.Button("Generate", variant="primary", size="lg", scale=2, visible=False)clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=False)search_toggle = gr.Checkbox(label="🔍 Web search",value=False,visible=False)model_dropdown = gr.Dropdown(choices=[model['name'] for model in AVAILABLE_MODELS],value=AVAILABLE_MODELS[1]['name'], # DeepSeek V3label="Model",visible=False)gr.Markdown("**Quick start**", visible=False)with gr.Column(visible=False) as quick_examples_col:for i, demo_item in enumerate(DEMO_LIST[:3]):demo_card = gr.Button(value=demo_item['title'],4 unmodified linesfn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),outputs=input)if not tavily_client:gr.Markdown("⚠️ Web search unavailable", visible=False)else:gr.Markdown("✅ Web search available", visible=False)model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[1]['name']}", visible=False) # DeepSeek V3def on_model_change(model_name):for m in AVAILABLE_MODELS:if m['name'] == model_name:return m, f"**Model:** {m['name']}", update_image_input_visibility(m)return AVAILABLE_MODELS[1], f"**Model:** {AVAILABLE_MODELS[1]['name']}", update_image_input_visibility(AVAILABLE_MODELS[1]) # DeepSeek V3 fallbackdef save_prompt(input):return {setting: {"system": input}}model_dropdown.change(on_model_change,inputs=model_dropdown,outputs=[current_model, model_display, image_input])with gr.Accordion("Advanced", open=False, visible=False) as advanced_accordion:systemPromptInput = gr.Textbox(value=SystemPrompt,label="System prompt",2 unmodified linessave_prompt_btn = gr.Button("Save", variant="primary", size="sm")save_prompt_btn.click(save_prompt, inputs=systemPromptInput, outputs=setting)# Timer-based login state pollinglogin_state = gr.State(False)timer = gr.Timer(1, active=True)def check_login(label, last_state):logged_in = label.startswith("Logout (")# Only update if state changesif last_state == logged_in:return [gr.skip()] * 12 # skip updating all outputsreturn (logged_in, # login_stategr.update(visible=not logged_in), # login_required_msggr.update(visible=logged_in), # inputgr.update(visible=logged_in), # website_url_inputgr.update(visible=logged_in), # file_inputgr.update(visible=logged_in), # btngr.update(visible=logged_in), # clear_btngr.update(visible=logged_in), # search_togglegr.update(visible=logged_in), # model_dropdowngr.update(visible=logged_in), # quick_examples_colgr.update(visible=logged_in), # advanced_accordionlogged_in, # update last_login_state)timer.tick(fn=check_login,inputs=[login_button, last_login_state],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])with gr.Column():with gr.Tabs():with gr.Tab("Code"):
app.py+51-41