import gradio as gr from chat import chat_with_model # streaming generator TITLE = "🧭 Apertus-8B Instruct — Perspective Chatbot" with gr.Blocks() as demo: gr.Markdown(f"# {TITLE}") with gr.Tab("💬 Chat"): perspective = gr.Textbox( label="Perspective (optional)", placeholder="e.g., 'Adopt the perspective of ...'", ) chatbot = gr.Chatbot(type="messages") msg = gr.Textbox(placeholder="Ask me anything…", show_label=False) state = gr.State([]) # stores conversation in messages format # Wire the streaming generator: yields (chatbot_messages, state_messages) msg.submit(chat_with_model, [msg, state, perspective], [chatbot, state]) gr.Markdown( "Tip: The perspective acts as a system prompt and is re-injected every turn, " "so it remains active during this session. Refreshing the page clears memory." ) demo.launch(server_name="0.0.0.0", server_port=7860)