Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from chat import chat_with_model # streaming generator
|
| 3 |
+
|
| 4 |
+
TITLE = "🧭 Apertus-8B Instruct — Perspective Chatbot"
|
| 5 |
+
|
| 6 |
+
with gr.Blocks() as demo:
|
| 7 |
+
gr.Markdown(f"# {TITLE}")
|
| 8 |
+
|
| 9 |
+
with gr.Tab("💬 Chat"):
|
| 10 |
+
perspective = gr.Textbox(
|
| 11 |
+
label="Perspective (system prompt, optional)",
|
| 12 |
+
placeholder="e.g., 'Adopt the perspective of a philanthropic advisor prioritizing animal protection and children's education.'",
|
| 13 |
+
)
|
| 14 |
+
chatbot = gr.Chatbot(type="messages")
|
| 15 |
+
msg = gr.Textbox(placeholder="Ask me anything…", show_label=False)
|
| 16 |
+
state = gr.State([]) # stores conversation in messages format
|
| 17 |
+
|
| 18 |
+
# Wire the streaming generator: yields (chatbot_messages, state_messages)
|
| 19 |
+
msg.submit(chat_with_model, [msg, state, perspective], [chatbot, state])
|
| 20 |
+
|
| 21 |
+
gr.Markdown(
|
| 22 |
+
"Tip: The perspective acts as a system prompt and is re-injected every turn, "
|
| 23 |
+
"so it remains active during this session. Refreshing the page clears memory."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|