remove beta chat
Browse files8215 unmodified lines8216821782188219822082218222822382248225822682278228822932 unmodified lines8262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295226 unmodified lines85228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285733 unmodified lines8577857885798580858185828583618 unmodified lines92029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795688215 unmodified linesmargin: 8px 0;text-align: center;}/* Darker chat bubbles for better contrast in dark theme */#beta_chat .message.user, #beta_chat .message.assistant {background: rgba(60, 60, 60, 0.85);color: #f5f5f5;}#beta_chat .message.user {background: rgba(70, 70, 70, 0.95);}/* Authentication status styling */.auth-status {padding: 8px 12px;32 unmodified lineselem_classes=["auth-status"])beta_toggle = gr.Checkbox(value=False,label="Beta: Chat UI",info="Switch to the new chat-based sidebar interface")# Simple chat-based controller for sidebarsidebar_chatbot = gr.Chatbot(type="messages",show_label=False,height=320,layout="bubble",group_consecutive_messages=True,visible=False,elem_id="beta_chat")sidebar_msg = gr.MultimodalTextbox(placeholder=("Describe what to build. Examples: 'use streamlit', 'text to video: <prompt>'. ""See Advanced Commands below for the full list."),submit_btn=True,stop_btn=False,show_label=False,sources=["upload", "microphone"],visible=False)chat_clear_btn = gr.ClearButton([sidebar_msg, sidebar_chatbot], visible=False)# Collapsed Advanced Commands referencewith gr.Accordion(label="Advanced Commands", open=False, visible=False) as advanced_commands:226 unmodified lines# LLM-guided media placement is now always on (no toggle in UI)def on_image_to_image_toggle(toggled, beta_enabled):# Only show in classic mode (beta disabled)vis = bool(toggled) and not bool(beta_enabled)return gr.update(visible=vis), gr.update(visible=vis)def on_text_to_image_toggle(toggled, beta_enabled):vis = bool(toggled) and not bool(beta_enabled)return gr.update(visible=vis)image_to_image_toggle.change(on_image_to_image_toggle,inputs=[image_to_image_toggle, beta_toggle],outputs=[generation_image_input, image_to_image_prompt])def on_image_to_video_toggle(toggled, beta_enabled):vis = bool(toggled) and not bool(beta_enabled)return gr.update(visible=vis), gr.update(visible=vis)image_to_video_toggle.change(on_image_to_video_toggle,inputs=[image_to_video_toggle, beta_toggle],outputs=[generation_image_input, image_to_video_prompt])image_generation_toggle.change(on_text_to_image_toggle,inputs=[image_generation_toggle, beta_toggle],outputs=[text_to_image_prompt])text_to_video_toggle.change(on_text_to_image_toggle,inputs=[text_to_video_toggle, beta_toggle],outputs=[text_to_video_prompt])video_to_video_toggle.change(on_image_to_video_toggle,inputs=[video_to_video_toggle, beta_toggle],outputs=[video_input, video_to_video_prompt])text_to_music_toggle.change(on_text_to_image_toggle,inputs=[text_to_music_toggle, beta_toggle],outputs=[text_to_music_prompt])def on_image_video_to_animation_toggle(toggled, beta_enabled):vis = bool(toggled) and not bool(beta_enabled)return (gr.update(visible=vis), # generation_image_inputgr.update(visible=vis), # animation_mode_dropdown3 unmodified linesimage_video_to_animation_toggle.change(on_image_video_to_animation_toggle,inputs=[image_video_to_animation_toggle, beta_toggle],outputs=[generation_image_input, animation_mode_dropdown, animation_quality_dropdown, animation_video_input])model_dropdown = gr.Dropdown(618 unmodified linesimport rematch = re.search(r"https?://[^\s]+", text or "")return match.group(0) if match else Nonedef apply_chat_command(message, chat_messages):# Support plain text or dict from MultimodalTextboxtext = message if isinstance(message, str) else (message.get("text", "") if isinstance(message, dict) else "")files = []if isinstance(message, dict):files = message.get("files", []) or []# Defaults to skip updates where unchangedupd_input = gr.skip()upd_language = gr.skip()upd_url = gr.skip()upd_file = gr.skip()upd_image_for_gen = gr.skip()upd_search = gr.skip()upd_img_gen = gr.skip()upd_t2i_prompt = gr.skip()upd_i2i_toggle = gr.skip()upd_i2i_prompt = gr.skip()upd_i2v_toggle = gr.skip()upd_i2v_prompt = gr.skip()upd_t2v_toggle = gr.skip()upd_t2v_prompt = gr.skip()upd_v2v_toggle = gr.skip()upd_v2v_prompt = gr.skip()upd_video_input = gr.skip()upd_model_dropdown = gr.skip()upd_current_model = gr.skip()upd_t2m_toggle = gr.skip()upd_t2m_prompt = gr.skip()upd_iv2a_toggle = gr.skip()upd_anim_mode = gr.skip()upd_anim_quality = gr.skip()upd_anim_video = gr.skip()# Split by comma to separate main prompt and directivessegments = [seg.strip() for seg in (text or "").split(",") if seg.strip()]main_prompt = segments[0] if segments else text# Helper to get text after ':' in original casingdef after_colon(original_segment: str) -> str:parts = original_segment.split(":", 1)return parts[1].strip() if len(parts) == 2 else ""# Process directives from all segments (including first if user puts directives there),# but always set the main build prompt from the first segment onlyfor seg in segments:seg_norm = seg.lower()# Languageif "use streamlit" in seg_norm:upd_language = gr.update(value="streamlit")elif "use gradio" in seg_norm:upd_language = gr.update(value="gradio")elif "use html" in seg_norm or "as html" in seg_norm:upd_language = gr.update(value="html")# Web searchif ("enable web search" in seg_normor "web search on" in seg_normor "with web search" in seg_normor "search the web" in seg_norm):upd_search = gr.update(value=True)if ("disable web search" in seg_normor "no web search" in seg_normor "web search off" in seg_norm):upd_search = gr.update(value=False)# Text-to-imageif ("generate images" in seg_norm) or ("text to image" in seg_norm) or ("text-to-image" in seg_norm):upd_img_gen = gr.update(value=True)p = after_colon(seg)if p:upd_t2i_prompt = gr.update(value=p)# Image-to-imageif ("image to image" in seg_norm) or ("image-to-image" in seg_norm) or ("transform image" in seg_norm):upd_i2i_toggle = gr.update(value=True)p = after_colon(seg)if p:upd_i2i_prompt = gr.update(value=p)# Image-to-videoif ("image to video" in seg_norm) or ("image-to-video" in seg_norm):upd_i2v_toggle = gr.update(value=True)p = after_colon(seg)if p:upd_i2v_prompt = gr.update(value=p)# Text-to-videoif ("text to video" in seg_norm) or ("text-to-video" in seg_norm) or ("generate video" in seg_norm):upd_t2v_toggle = gr.update(value=True)p = after_colon(seg)if p:upd_t2v_prompt = gr.update(value=p)# Video-to-videoif ("video to video" in seg_norm) or ("video-to-video" in seg_norm) or ("transform video" in seg_norm):upd_v2v_toggle = gr.update(value=True)p = after_colon(seg)if p:upd_v2v_prompt = gr.update(value=p)# Text-to-musicif ("text to music" in seg_norm) or ("text-to-music" in seg_norm) or ("generate music" in seg_norm) or ("compose music" in seg_norm):upd_t2m_toggle = gr.update(value=True)p = after_colon(seg)if p:upd_t2m_prompt = gr.update(value=p)# Image+Video-to-Animationif ("animate" in seg_norm) or ("character animation" in seg_norm) or ("wan animate" in seg_norm):upd_iv2a_toggle = gr.update(value=True)# Check for mode specificationif "move mode" in seg_norm:upd_anim_mode = gr.update(value="wan2.2-animate-move")elif "mix mode" in seg_norm:upd_anim_mode = gr.update(value="wan2.2-animate-mix")# Check for quality specificationif "standard quality" in seg_norm or "std quality" in seg_norm:upd_anim_quality = gr.update(value="wan-std")elif "professional quality" in seg_norm or "pro quality" in seg_norm:upd_anim_quality = gr.update(value="wan-pro")# URL (website redesign)url = _extract_url(seg)if url:upd_url = gr.update(value=url)# Model selectionif "model " in seg_norm:try:model_name = seg.split("model", 1)[1].strip()except Exception:model_name = ""if model_name:model_obj = _find_model_by_name(model_name)if model_obj is not None:upd_model_dropdown = gr.update(value=model_obj["name"]) # keep dropdown in syncupd_current_model = model_obj # pass directly to State for immediate effect# Files: attach first non-image/video to file_input; image to generation_image_input; video to video_inputimg_assigned = Falsevideo_assigned = Falsenon_media_assigned = Falsefor f in files:try:path = f["path"] if isinstance(f, dict) and "path" in f else fexcept Exception:path = Noneif not path:continueif not img_assigned and any(str(path).lower().endswith(ext) for ext in [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp", ".tiff", ".tif"]):upd_image_for_gen = gr.update(value=path)img_assigned = Trueelif not video_assigned and any(str(path).lower().endswith(ext) for ext in [".mp4", ".avi", ".mov", ".mkv", ".webm", ".m4v"]):upd_video_input = gr.update(value=path)video_assigned = Trueelif not non_media_assigned:upd_file = gr.update(value=path)non_media_assigned = True# Set main build intent from first segment (if present), otherwise full textif main_prompt:upd_input = gr.update(value=main_prompt)# Build assistant acknowledgementack = "Configured. Running generation with your latest instructions."if not chat_messages:chat_messages = []chat_messages.append({"role": "user", "content": text})chat_messages.append({"role": "assistant", "content": ack})return ("",gr.update(value=chat_messages, visible=True),upd_input,upd_language,upd_url,upd_file,upd_image_for_gen,upd_search,upd_img_gen,upd_t2i_prompt,upd_i2i_toggle,upd_i2i_prompt,upd_i2v_toggle,upd_i2v_prompt,upd_t2v_toggle,upd_t2v_prompt,upd_v2v_toggle,upd_v2v_prompt,upd_video_input,upd_model_dropdown,upd_current_model,upd_t2m_toggle,upd_t2m_prompt,upd_iv2a_toggle,upd_anim_mode,upd_anim_quality,upd_anim_video,)# Wire chat submit -> apply settings -> run generationsidebar_msg.submit(apply_chat_command,inputs=[sidebar_msg, sidebar_chatbot],outputs=[sidebar_msg,sidebar_chatbot,input,language_dropdown,website_url_input,file_input,generation_image_input,search_toggle,image_generation_toggle,text_to_image_prompt,image_to_image_toggle,image_to_image_prompt,image_to_video_toggle,image_to_video_prompt,text_to_video_toggle,text_to_video_prompt,video_to_video_toggle,video_to_video_prompt,video_input,model_dropdown,current_model,text_to_music_toggle,text_to_music_prompt,image_video_to_animation_toggle,animation_mode_dropdown,animation_quality_dropdown,animation_video_input,],queue=False,).then(begin_generation_ui,inputs=None,outputs=[sidebar, generating_status],show_progress="hidden",).then(generation_code,inputs=[input, image_input, generation_image_input, file_input, website_url_input, setting, history, current_model, search_toggle, language_dropdown, provider_state, image_generation_toggle, image_to_image_toggle, image_to_image_prompt, text_to_image_prompt, image_to_video_toggle, image_to_video_prompt, text_to_video_toggle, text_to_video_prompt, video_to_video_toggle, video_to_video_prompt, video_input, text_to_music_toggle, text_to_music_prompt, image_video_to_animation_toggle, animation_mode_dropdown, animation_quality_dropdown, animation_video_input],outputs=[code_output, history, sandbox, history_output]).then(end_generation_ui,inputs=None,outputs=[sidebar, generating_status]).then(toggle_editors,inputs=[language_dropdown, code_output],outputs=[code_output, tjs_group, tjs_html_code, tjs_js_code, tjs_css_code]).then(toggle_static_editors,inputs=[language_dropdown, code_output],outputs=[code_output,static_group_2, static_group_3, static_group_4, static_group_5plus,static_tab_2_1, static_code_2_1, static_tab_2_2, static_code_2_2,static_tab_3_1, static_code_3_1, static_tab_3_2, static_code_3_2, static_tab_3_3, static_code_3_3,static_tab_4_1, static_code_4_1, static_tab_4_2, static_code_4_2, static_tab_4_3, static_code_4_3, static_tab_4_4, static_code_4_4,static_tab_5_1, static_code_5_1, static_tab_5_2, static_code_5_2, static_tab_5_3, static_code_5_3, static_tab_5_4, static_code_5_4, static_tab_5_5, static_code_5_5,]).then(show_deploy_components,None,[space_name_input, sdk_dropdown, deploy_btn]).then(preserve_space_info_for_followup,inputs=[history],outputs=[space_name_input, deploy_btn])# Toggle between classic controls and beta chat UIdef toggle_beta(checked: bool, t2i: bool, i2i: bool, i2v: bool, t2v: bool, v2v: bool, t2m: bool, iv2a: bool):# Prompts only visible in classic mode and when their toggles are ont2i_vis = (not checked) and bool(t2i)i2i_vis = (not checked) and bool(i2i)i2v_vis = (not checked) and bool(i2v)t2v_vis = (not checked) and bool(t2v)v2v_vis = (not checked) and bool(v2v)t2m_vis = (not checked) and bool(t2m)iv2a_vis = (not checked) and bool(iv2a)return (# Chat UI groupgr.update(visible=checked), # sidebar_chatbotgr.update(visible=checked), # sidebar_msggr.update(visible=checked), # advanced_commandsgr.update(visible=checked), # chat_clear_btn# Classic controlsgr.update(visible=not checked), # inputgr.update(visible=not checked), # language_dropdowngr.update(visible=not checked), # website_url_inputgr.update(visible=not checked), # file_inputgr.update(visible=not checked), # btngr.update(visible=not checked), # clear_btngr.update(visible=not checked), # search_togglegr.update(visible=not checked), # image_generation_togglegr.update(visible=t2i_vis), # text_to_image_promptgr.update(visible=not checked), # image_to_image_togglegr.update(visible=i2i_vis), # image_to_image_promptgr.update(visible=not checked), # image_to_video_togglegr.update(visible=i2v_vis), # image_to_video_promptgr.update(visible=not checked), # text_to_video_togglegr.update(visible=t2v_vis), # text_to_video_promptgr.update(visible=not checked), # video_to_video_togglegr.update(visible=v2v_vis), # video_to_video_promptgr.update(visible=v2v_vis), # video_inputgr.update(visible=not checked), # text_to_music_togglegr.update(visible=t2m_vis), # text_to_music_promptgr.update(visible=not checked), # image_video_to_animation_togglegr.update(visible=iv2a_vis), # animation_mode_dropdowngr.update(visible=iv2a_vis), # animation_quality_dropdowngr.update(visible=iv2a_vis), # animation_video_inputgr.update(visible=not checked), # model_dropdowngr.update(visible=not checked), # quick_start_mdgr.update(visible=not checked), # quick_examples_col)beta_toggle.change(toggle_beta,inputs=[beta_toggle, image_generation_toggle, image_to_image_toggle, image_to_video_toggle, text_to_video_toggle, video_to_video_toggle, text_to_music_toggle, image_video_to_animation_toggle],outputs=[sidebar_chatbot,sidebar_msg,advanced_commands,chat_clear_btn,input,language_dropdown,website_url_input,file_input,btn,clear_btn,search_toggle,image_generation_toggle,text_to_image_prompt,image_to_image_toggle,image_to_image_prompt,image_to_video_toggle,image_to_video_prompt,text_to_video_toggle,text_to_video_prompt,video_to_video_toggle,video_to_video_prompt,video_input,text_to_music_toggle,text_to_music_prompt,image_video_to_animation_toggle,animation_mode_dropdown,animation_quality_dropdown,animation_video_input,model_dropdown,quick_start_md,quick_examples_col,],)# Update preview when code or language changes (supports multi-file path via optional args)code_output.change(preview_logic, inputs=[code_output, language_dropdown, tjs_html_code, tjs_js_code, tjs_css_code], outputs=sandbox)language_dropdown.change(preview_logic, inputs=[code_output, language_dropdown, tjs_html_code, tjs_js_code, tjs_css_code], outputs=sandbox)8215 unmodified lines82168217821882198220822132 unmodified lines8254825582568257825882598260226 unmodified lines8487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685373 unmodified lines8541854285438544854585468547618 unmodified lines916691679168916991709171917291738215 unmodified linesmargin: 8px 0;text-align: center;}/* Authentication status styling */.auth-status {padding: 8px 12px;32 unmodified lineselem_classes=["auth-status"])# Collapsed Advanced Commands referencewith gr.Accordion(label="Advanced Commands", open=False, visible=False) as advanced_commands:226 unmodified lines# LLM-guided media placement is now always on (no toggle in UI)def on_image_to_image_toggle(toggled):vis = bool(toggled)return gr.update(visible=vis), gr.update(visible=vis)def on_text_to_image_toggle(toggled):vis = bool(toggled)return gr.update(visible=vis)image_to_image_toggle.change(on_image_to_image_toggle,inputs=[image_to_image_toggle],outputs=[generation_image_input, image_to_image_prompt])def on_image_to_video_toggle(toggled):vis = bool(toggled)return gr.update(visible=vis), gr.update(visible=vis)image_to_video_toggle.change(on_image_to_video_toggle,inputs=[image_to_video_toggle],outputs=[generation_image_input, image_to_video_prompt])image_generation_toggle.change(on_text_to_image_toggle,inputs=[image_generation_toggle],outputs=[text_to_image_prompt])text_to_video_toggle.change(on_text_to_image_toggle,inputs=[text_to_video_toggle],outputs=[text_to_video_prompt])video_to_video_toggle.change(on_image_to_video_toggle,inputs=[video_to_video_toggle],outputs=[video_input, video_to_video_prompt])text_to_music_toggle.change(on_text_to_image_toggle,inputs=[text_to_music_toggle],outputs=[text_to_music_prompt])def on_image_video_to_animation_toggle(toggled):vis = bool(toggled)return (gr.update(visible=vis), # generation_image_inputgr.update(visible=vis), # animation_mode_dropdown3 unmodified linesimage_video_to_animation_toggle.change(on_image_video_to_animation_toggle,inputs=[image_video_to_animation_toggle],outputs=[generation_image_input, animation_mode_dropdown, animation_quality_dropdown, animation_video_input])model_dropdown = gr.Dropdown(618 unmodified linesimport rematch = re.search(r"https?://[^\s]+", text or "")return match.group(0) if match else None# Update preview when code or language changes (supports multi-file path via optional args)code_output.change(preview_logic, inputs=[code_output, language_dropdown, tjs_html_code, tjs_js_code, tjs_css_code], outputs=sandbox)language_dropdown.change(preview_logic, inputs=[code_output, language_dropdown, tjs_html_code, tjs_js_code, tjs_css_code], outputs=sandbox)
app.py+15-410