AperPhil / app.py
luciagomez's picture
Create app.py
7aa706b verified
raw
history blame
1.08 kB
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 (system prompt, optional)",
placeholder="e.g., 'Adopt the perspective of a philanthropic advisor prioritizing animal protection and children's education.'",
)
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)