Spaces:
Running
Running
Update app.py
Browse files79 unmodified lines8081828384858630 unmodified lines1171181191201211221235 unmodified lines12913013113213313413515 unmodified lines15115215315415515615715815918 unmodified lines1781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192205 unmodified lines2262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652667 unmodified lines2742752762772782792802812822832842852862872882892902912922932942952962972985 unmodified lines30430530630730830931031131231331431521 unmodified lines3373383393403413423431 unmodified line3453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105111 unmodified line5135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495504 unmodified lines55555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961010 unmodified lines6216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616622 unmodified lines66566666766866967067167267367467567667767867968068168268368468568668768868969079 unmodified linesmodel_locks = [threading.Lock() for _ in range(NUM_MODEL_COPIES)]print(f"All {NUM_MODEL_COPIES} model copies loaded!")# ── Aiko-specific config ──────────────────────────────────────────────────────JSON_PREFIX = '{"internal_monologue":"'GEN_CONFIG = dict(30 unmodified lines# ── JSON extraction ───────────────────────────────────────────────────────────def extract_aiko_data(text):"""Try multiple strategies to extract valid JSON from Aiko output"""try:return json.loads(text)except:5 unmodified linesexcept:pass# Regex fallbackdata = {}m = re.search(r'"internal_monologue"\s*:\s*"((?:[^"\\]|\\.)*)"', text)data["internal_monologue"] = m.group(1) if m else ""15 unmodified linesreturn data if data.get("response") else None# ── Build Aiko prompt ─────────────────────────────────────────────────────────def build_aiko_prompt(history, user_msg, location="middle of the apartment"):"""Build multi-turn prompt in Aiko's expected format"""parts = []for past_user, past_json in history:parts.append(f"[user] Location: {location} | Player user: {past_user}")18 unmodified linesstreamer.text_queue.put(streamer.stop_signal)raise# ── Format Aiko response for display ──────────────────────────────────────────def format_aiko_display(data):"""Format Aiko's JSON response into pretty markdown"""if not data:return "*Aiko looks at you, confused...*"monologue = data.get("internal_monologue", "")response = data.get("response", "...")emotion = data.get("emotion", "?")# Build displayparts = []# Emotion + monologueemotion_emoji = {"Happy": "😊", "Sad": "😢", "Angry": "😡", "Worried": "😟","Scared": "😨", "Surprised": "😲", "Disgusted": "🤢","Neutral": "😐", "Excited": "🤩", "Confused": "😕",}.get(emotion, "💭")if monologue:parts.append(f"*{emotion_emoji} [{emotion}] {monologue}*")parts.append("") # blank line# Main response (clean up speech speed markers for display)parts.append(response)# Behavioral flagsflags = []flag_labels = {'red_eyes': '🔴 red eyes','is_angry': '😡 angry','is_following': '👣 following','is_suspicious': '🤨 suspicious','is_threatening': '⚠️ threatening','open_main_door': '🚪 door open','DontLetPlayerLeave': '🚫 won\'t let you leave',}for flag, label in flag_labels.items():if data.get(flag):5 unmodified linesreturn "\n".join(parts)# ── Aiko chat history storage (separate from gradio display history) ─────────aiko_histories = {} # session_id → list of (user, full_json)def respond(message: str, history: list, api_key: str, location: str):if not validate_key(api_key):yield "🔒 *unauthorized — invalid access key*"returnif not queue_counter.acquire(blocking=False):yield "💔 *Aiko is busy with someone else... try again shortly*"returntry:# Convert gradio history → aiko format# We need to reconstruct (user, raw_json) pairs from display history# Use a hash of history as a keyhistory_key = str(id(history))aiko_history = aiko_histories.get(history_key, [])# If display history shrank, reset aiko historyexpected_len = len(history)if len(aiko_history) > expected_len:aiko_history = aiko_history[:expected_len]# Trim to last 6 turnsif len(aiko_history) > 6:aiko_history = aiko_history[-6:]# Build promptprompt = build_aiko_prompt(aiko_history, message, location)# Get free modelidx, model_instance = acquire_free_model(timeout=60.0)if model_instance is None:yield "💔 *Aiko is overwhelmed... try again*"returnaccumulated = ""7 unmodified linesfuture = executor.submit(_run_generation, model_instance, prompt, streamer)# Stream tokens — show progressive parsingfor token in streamer:accumulated += token# Try to extract partial data and displayfull_text = JSON_PREFIX + accumulateddata = extract_aiko_data(full_text)if data and data.get("response"):yield format_aiko_display(data)future.result(timeout=10)# Final parse + save to historyfull_text = JSON_PREFIX + accumulateddata = extract_aiko_data(full_text)if data and data.get("response"):# Find clean JSON to savetry:end_idx = full_text.rindex('}') + 1clean_json = full_text[:end_idx]5 unmodified linesyield format_aiko_display(data)else:yield "💔 *Aiko stares blankly at you...*"except Exception as e:logger.error(f"respond() error on model #{idx}: {e}")if not accumulated:yield "💔 *Aiko seems to be having an episode... try again*"finally:model_locks[idx].release()21 unmodified lineslogger.info(f"Model #{idx} warmup: {time.time()-t0:.1f}s ✓")except Exception as e:logger.warning(f"Model #{idx} warmup failed: {e}")logger.info("All warmups complete ✓")except Exception as e:logger.warning(f"Warmup failed: {e}")1 unmodified lineThread(target=_warmup, daemon=True).start()# ── CSS — Dark Romantic Theme ─────────────────────────────────────────────────custom_css = """@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=Inter:wght@300;400;500&display=swap');* { font-family: 'Inter', sans-serif !important; }html, body, .gradio-container, .main, .wrap, gradio-app {background: linear-gradient(135deg, #1a0d1f 0%, #2d1430 50%, #1a0d1f 100%) !important;color: #f5e6f0 !important;min-height: 100vh !important;}.gradio-container {max-width: 900px !important;margin: 0 auto !important;padding: 20px !important;}/* Subtle vignette */body::before {content: '';position: fixed;top: 0; left: 0; right: 0; bottom: 0;background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.4) 100%);pointer-events: none;z-index: 1;}/* Headers */h1, h2, h3 {font-family: 'Cormorant Garamond', serif !important;color: #ff6b9d !important;text-shadow: 0 0 20px rgba(255, 107, 157, 0.3);text-align: center;font-weight: 700 !important;letter-spacing: 2px;}h1 { font-size: 36px !important; margin-bottom: 5px !important; }h3 { font-size: 16px !important; color: #d4a5c7 !important; font-style: italic; }/* Chatbot container */.chatbot, [data-testid="chatbot"], .message-wrap, .messages {background: rgba(15, 8, 18, 0.6) !important;border: 1px solid rgba(255, 107, 157, 0.2) !important;border-radius: 12px !important;box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5),inset 0 0 60px rgba(255, 107, 157, 0.05) !important;backdrop-filter: blur(10px);}/* User messages — soft pink */.message.user .message-bubble-border,div[data-testid="user"] .message-bubble-border,.message.user {background: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%) !important;color: #ffffff !important;border: none !important;border-radius: 18px 18px 4px 18px !important;box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3) !important;font-size: 14px !important;line-height: 1.6 !important;padding: 12px 16px !important;}/* Bot messages — dark with pink border */.message.bot .message-bubble-border,div[data-testid="bot"] .message-bubble-border,.message.bot {background: rgba(45, 20, 48, 0.9) !important;color: #f5e6f0 !important;border: 1px solid rgba(255, 107, 157, 0.3) !important;border-radius: 18px 18px 18px 4px !important;box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;font-size: 14px !important;line-height: 1.7 !important;padding: 14px 18px !important;}.message.user *, .message.user p { color: #ffffff !important; }.message.bot *, .message.bot p { color: #f5e6f0 !important; }/* Italic monologue */.message.bot em, .message.bot i {color: #d4a5c7 !important;font-style: italic;display: block;margin-bottom: 8px;font-size: 13px;opacity: 0.85;}/* Code blocks (for flags) */.message.bot code {background: rgba(255, 107, 157, 0.15) !important;color: #ff9ec7 !important;padding: 4px 10px !important;border-radius: 6px !important;font-size: 11px !important;border: 1px solid rgba(255, 107, 157, 0.3) !important;display: inline-block !important;margin-top: 8px !important;}/* Avatars */.avatar-container, .avatar-container img, img.avatar-image {width: 42px !important;height: 42px !important;min-width: 42px !important;border-radius: 50% !important;border: 2px solid rgba(255, 107, 157, 0.4) !important;box-shadow: 0 0 12px rgba(255, 107, 157, 0.3) !important;}/* Input area */textarea, input[type="text"] {background: rgba(15, 8, 18, 0.8) !important;color: #f5e6f0 !important;border: 1px solid rgba(255, 107, 157, 0.4) !important;border-radius: 12px !important;font-size: 14px !important;padding: 14px 18px !important;box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3) !important;transition: all 0.3s ease !important;}textarea:focus, input[type="text"]:focus {border-color: #ff6b9d !important;box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.2),inset 0 2px 8px rgba(0, 0, 0, 0.3) !important;outline: none !important;}textarea::placeholder, input::placeholder {color: rgba(212, 165, 199, 0.5) !important;font-style: italic;}/* Buttons */button {background: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%) !important;color: #ffffff !important;border: none !important;border-radius: 10px !important;font-size: 13px !important;font-weight: 500 !important;padding: 10px 24px !important;letter-spacing: 0.5px !important;box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3) !important;transition: all 0.3s ease !important;cursor: pointer !important;}button:hover {transform: translateY(-2px) !important;box-shadow: 0 6px 16px rgba(255, 107, 157, 0.5) !important;background: linear-gradient(135deg, #ff7ba8 0%, #d45578 100%) !important;}button:active {transform: translateY(0) !important;}/* Lock screen */1 unmodified lineposition: fixed !important;top: 0 !important; left: 0 !important;width: 100vw !important; height: 100vh !important;background: linear-gradient(135deg, #1a0d1f 0%, #2d1430 50%, #1a0d1f 100%) !important;z-index: 9999 !important;display: flex !important;flex-direction: column !important;align-items: center !important;justify-content: center !important;gap: 24px !important;}#lock-screen h1 {font-size: 48px !important;background: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;background-clip: text;text-shadow: none !important;margin: 0 !important;}#lock-screen h3 {margin-top: 0 !important;color: #d4a5c7 !important;font-weight: 300 !important;}#lock-screen input {width: 320px !important;max-width: 80vw !important;}#lock-screen button {width: 200px !important;}/* Misc */4 unmodified linesborder: none !important;}/* Location selector */.location-container {background: rgba(15, 8, 18, 0.6) !important;border: 1px solid rgba(255, 107, 157, 0.2) !important;border-radius: 10px !important;padding: 12px !important;margin-bottom: 12px !important;}label, .label {color: #d4a5c7 !important;font-size: 12px !important;text-transform: uppercase !important;letter-spacing: 1px !important;font-weight: 500 !important;}/* Heart decorations */.heart-divider {text-align: center;color: #ff6b9d;font-size: 14px;margin: 10px 0;opacity: 0.5;}/* Scrollbar */::-webkit-scrollbar { width: 8px; }::-webkit-scrollbar-track { background: rgba(15, 8, 18, 0.5); }::-webkit-scrollbar-thumb {background: linear-gradient(180deg, #ff6b9d, #c44569);border-radius: 4px;}/* Dropdown */select, .gr-dropdown {background: rgba(15, 8, 18, 0.8) !important;color: #f5e6f0 !important;border: 1px solid rgba(255, 107, 157, 0.4) !important;border-radius: 10px !important;padding: 10px 14px !important;font-size: 13px !important;}"""# Default avatars (you can replace these)USER_AVATAR = None # gradio defaultBOT_AVATAR = None # could use an Aiko portrait# Available locationsLOCATIONS = ["middle of the apartment","living room",10 unmodified lines# Lock screenwith gr.Column(elem_id="lock-screen", visible=True) as lock_screen:gr.Markdown("# Aiko")gr.Markdown("### *she's been waiting for you...*")key_input = gr.Textbox(placeholder="enter access key...",type="password",show_label=False,max_lines=1,)unlock_btn = gr.Button("✦ ENTER ✦")lock_msg = gr.Markdown("")# Chat screenwith gr.Column(visible=False) as chat_screen:gr.Markdown("# Aiko")gr.Markdown("### *your devoted companion*")gr.HTML('<div class="heart-divider">❀ ───────────── ❀</div>')stored_key = gr.Textbox(value="", visible=False)# Location selectorwith gr.Row(elem_classes="location-container"):location_dropdown = gr.Dropdown(choices=LOCATIONS,value="middle of the apartment",label="📍 Current Location",interactive=True,scale=2,)chatbot = gr.Chatbot(type = "messages",avatar_images = (USER_AVATAR, BOT_AVATAR),height = 550,show_label = False,bubble_full_width = False,show_copy_button = False,placeholder = "<center><i>Aiko is waiting to chat with you...</i></center>",)gr.ChatInterface(2 unmodified linestype = "messages",additional_inputs = [stored_key, location_dropdown],additional_inputs_accordion = gr.Accordion(visible=False),examples = [["hey aiko", "", "middle of the apartment"],["how are you?", "", "middle of the apartment"],["what are you thinking about?", "", "bedroom"],["i love you", "", "middle of the apartment"],["i need to leave", "", "front door"],],)gr.HTML('<div class="heart-divider">❀ ───────────── ❀</div>')gr.Markdown("<center style='color: #d4a5c7; font-size: 11px; opacity: 0.7;'>""<i>Powered by Aiko-350M • A fictional character simulation</i>""</center>")def try_unlock(key):if validate_key(key):return gr.update(visible=False), gr.update(visible=True), key, ""return gr.update(visible=True), gr.update(visible=False), "", "*invalid key — try again...*"for trigger in (unlock_btn.click, key_input.submit):trigger(fn=try_unlock, inputs=[key_input],79 unmodified lines8081828384858630 unmodified lines1171181191201211225 unmodified lines12812913013113213315 unmodified lines14915015115215315415515618 unmodified lines1751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052065 unmodified lines2122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442457 unmodified lines2532542552562572582592602612622632642652662672682692702715 unmodified lines27727827928028128228328428528628728821 unmodified lines3103113123133143151 unmodified line3173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574581 unmodified line4604614624634644654664674684694704714724734744754764774784794804814824834844854864 unmodified lines49149249349449549649749849950050150250350450550650750850951051151251351451551651751810 unmodified lines5295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625632 unmodified lines56656756856957057157257357457557657779 unmodified linesmodel_locks = [threading.Lock() for _ in range(NUM_MODEL_COPIES)]print(f"All {NUM_MODEL_COPIES} model copies loaded!")# ── Aiko config ───────────────────────────────────────────────────────────────JSON_PREFIX = '{"internal_monologue":"'GEN_CONFIG = dict(30 unmodified lines# ── JSON extraction ───────────────────────────────────────────────────────────def extract_aiko_data(text):try:return json.loads(text)except:5 unmodified linesexcept:passdata = {}m = re.search(r'"internal_monologue"\s*:\s*"((?:[^"\\]|\\.)*)"', text)data["internal_monologue"] = m.group(1) if m else ""15 unmodified linesreturn data if data.get("response") else None# ── Build prompt ──────────────────────────────────────────────────────────────def build_aiko_prompt(history, user_msg, location="middle of the apartment"):parts = []for past_user, past_json in history:parts.append(f"[user] Location: {location} | Player user: {past_user}")18 unmodified linesstreamer.text_queue.put(streamer.stop_signal)raise# ── Format display ────────────────────────────────────────────────────────────def format_aiko_display(data):if not data:return "..."monologue = data.get("internal_monologue", "")response = data.get("response", "...")emotion = data.get("emotion", "?")parts = []if monologue:parts.append(f"*[{emotion}] {monologue}*")parts.append("")parts.append(response)flags = []flag_labels = {'red_eyes': '🔴 red_eyes','is_angry': '😡 angry','is_following': '👣 following','is_suspicious': '🤨 suspicious','is_threatening': '⚠️ threatening','open_main_door': '🚪 door_open','DontLetPlayerLeave': '🚫 blocking_exit',}for flag, label in flag_labels.items():if data.get(flag):5 unmodified linesreturn "\n".join(parts)# ── Chat history storage ──────────────────────────────────────────────────────aiko_histories = {}def respond(message: str, history: list, api_key: str, location: str):if not validate_key(api_key):yield "unauthorized"returnif not queue_counter.acquire(blocking=False):yield "server busy — try again"returntry:history_key = str(id(history))aiko_history = aiko_histories.get(history_key, [])expected_len = len(history)if len(aiko_history) > expected_len:aiko_history = aiko_history[:expected_len]if len(aiko_history) > 6:aiko_history = aiko_history[-6:]prompt = build_aiko_prompt(aiko_history, message, location)idx, model_instance = acquire_free_model(timeout=60.0)if model_instance is None:yield "all models busy"returnaccumulated = ""7 unmodified linesfuture = executor.submit(_run_generation, model_instance, prompt, streamer)for token in streamer:accumulated += tokenfull_text = JSON_PREFIX + accumulateddata = extract_aiko_data(full_text)if data and data.get("response"):yield format_aiko_display(data)future.result(timeout=10)full_text = JSON_PREFIX + accumulateddata = extract_aiko_data(full_text)if data and data.get("response"):try:end_idx = full_text.rindex('}') + 1clean_json = full_text[:end_idx]5 unmodified linesyield format_aiko_display(data)else:yield "..."except Exception as e:logger.error(f"respond() error: {e}")if not accumulated:yield "generation failed"finally:model_locks[idx].release()21 unmodified lineslogger.info(f"Model #{idx} warmup: {time.time()-t0:.1f}s ✓")except Exception as e:logger.warning(f"Model #{idx} warmup failed: {e}")logger.info("All warmups complete ✓")except Exception as e:logger.warning(f"Warmup failed: {e}")1 unmodified lineThread(target=_warmup, daemon=True).start()# ── CSS — Simple Pink AI Theme ────────────────────────────────────────────────custom_css = """@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');* { font-family: 'Inter', sans-serif !important; }html, body, .gradio-container, .main, .wrap, gradio-app {background-color: #fafafa !important;color: #1a1a1a !important;}.gradio-container {max-width: 800px !important;margin: 0 auto !important;padding: 20px !important;}/* Headers */h1 {color: #ec4899 !important;font-weight: 700 !important;font-size: 28px !important;text-align: center !important;margin: 0 !important;}h3 {color: #6b7280 !important;font-weight: 400 !important;font-size: 14px !important;text-align: center !important;margin-top: 4px !important;}/* Chatbot */.chatbot, [data-testid="chatbot"], .message-wrap, .messages {background: #ffffff !important;border: 1px solid #f3e8ff !important;border-radius: 12px !important;box-shadow: 0 1px 3px rgba(236, 72, 153, 0.05) !important;}/* User messages — pink */.message.user .message-bubble-border,div[data-testid="user"] .message-bubble-border,.message.user {background: #ec4899 !important;color: #ffffff !important;border: none !important;border-radius: 16px 16px 4px 16px !important;font-size: 14px !important;line-height: 1.5 !important;padding: 10px 14px !important;}/* Bot messages — light pink */.message.bot .message-bubble-border,div[data-testid="bot"] .message-bubble-border,.message.bot {background: #fdf2f8 !important;color: #1a1a1a !important;border: 1px solid #fce7f3 !important;border-radius: 16px 16px 16px 4px !important;font-size: 14px !important;line-height: 1.6 !important;padding: 12px 16px !important;}.message.user *, .message.user p { color: #ffffff !important; }.message.bot *, .message.bot p { color: #1a1a1a !important; }/* Italic monologue */.message.bot em, .message.bot i {color: #ec4899 !important;font-style: italic;display: block;margin-bottom: 6px;font-size: 12px;opacity: 0.85;}/* Code (flags) */.message.bot code {background: #fce7f3 !important;color: #be185d !important;padding: 3px 8px !important;border-radius: 6px !important;font-size: 11px !important;font-family: 'Inter', sans-serif !important;display: inline-block !important;margin-top: 6px !important;}/* Avatars */.avatar-container, .avatar-container img, img.avatar-image {width: 36px !important;height: 36px !important;border-radius: 50% !important;}/* Input */textarea, input[type="text"] {background: #ffffff !important;color: #1a1a1a !important;border: 1px solid #fce7f3 !important;border-radius: 10px !important;font-size: 14px !important;padding: 10px 14px !important;transition: border-color 0.2s ease !important;}textarea:focus, input[type="text"]:focus {border-color: #ec4899 !important;box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.1) !important;outline: none !important;}textarea::placeholder, input::placeholder {color: #9ca3af !important;}/* Buttons */button {background: #ec4899 !important;color: #ffffff !important;border: none !important;border-radius: 8px !important;font-size: 13px !important;font-weight: 500 !important;padding: 8px 20px !important;transition: background-color 0.2s ease !important;cursor: pointer !important;}button:hover {background: #db2777 !important;}/* Lock screen */1 unmodified lineposition: fixed !important;top: 0 !important; left: 0 !important;width: 100vw !important; height: 100vh !important;background: #fafafa !important;z-index: 9999 !important;display: flex !important;flex-direction: column !important;align-items: center !important;justify-content: center !important;gap: 16px !important;}#lock-screen h1 {font-size: 36px !important;margin-bottom: 4px !important;}#lock-screen input {width: 280px !important;max-width: 80vw !important;}#lock-screen button {width: 160px !important;}/* Misc */4 unmodified linesborder: none !important;}label, .label {color: #6b7280 !important;font-size: 13px !important;font-weight: 500 !important;}/* Scrollbar */::-webkit-scrollbar { width: 6px; }::-webkit-scrollbar-track { background: #fafafa; }::-webkit-scrollbar-thumb { background: #ec4899; border-radius: 3px; }/* Dropdown */select, .gr-dropdown {background: #ffffff !important;color: #1a1a1a !important;border: 1px solid #fce7f3 !important;border-radius: 8px !important;padding: 8px 12px !important;font-size: 13px !important;}"""LOCATIONS = ["middle of the apartment","living room",10 unmodified lines# Lock screenwith gr.Column(elem_id="lock-screen", visible=True) as lock_screen:gr.Markdown("# Aiko")gr.Markdown("### enter access key")key_input = gr.Textbox(placeholder="access key",type="password",show_label=False,max_lines=1,)unlock_btn = gr.Button("ENTER")lock_msg = gr.Markdown("")# Chat screenwith gr.Column(visible=False) as chat_screen:gr.Markdown("# Aiko")stored_key = gr.Textbox(value="", visible=False)location_dropdown = gr.Dropdown(choices=LOCATIONS,value="middle of the apartment",label="Location",interactive=True,)chatbot = gr.Chatbot(type = "messages",height = 500,show_label = False,bubble_full_width = False,show_copy_button = False,)gr.ChatInterface(2 unmodified linestype = "messages",additional_inputs = [stored_key, location_dropdown],additional_inputs_accordion = gr.Accordion(visible=False),)def try_unlock(key):if validate_key(key):return gr.update(visible=False), gr.update(visible=True), key, ""return gr.update(visible=True), gr.update(visible=False), "", "invalid key"for trigger in (unlock_btn.click, key_input.submit):trigger(fn=try_unlock, inputs=[key_input],
app.py+104-217