VerdantClaw-Secure / simple-chat.py
TheEdict's picture
Add simple working chat that bypasses Marimo AI panel
97a6c2a verified
Raw
History Blame Contribute Delete
1.51 kB
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "marimo",
# "requests",
# ]
# ///
import marimo
__generated_with = "0.9.0"
app = marimo.App()
@app.cell
def _():
import marimo as mo
import requests
return mo, requests
@app.cell
def _(mo):
mo.md("# πŸ¦€ VerdantClaw Chat")
mo.md("**Simple chat with ZeroClaw**")
mo.md("---")
return
@app.cell
def _(mo, requests):
"""Simple working chat"""
mo.md("### πŸ’¬ Chat")
# Message input
msg = mo.ui.text(
label="",
placeholder="Type your message..."
)
# Send button
send = mo.ui.run_button(label="Send")
# Display input and button
mo.hstack([msg, send])
msg, send
return msg, send
@app.cell
def _(mo, requests, msg, send):
"""Process message"""
if send.value and msg.value:
try:
response = requests.post(
"http://localhost:42617/webhook",
json={"message": msg.value},
timeout=120
)
if response.status_code == 200:
result = response.json()
mo.md(f"**βœ… Response:** {result.get('response', 'No response')}")
else:
mo.md(f"❌ Error {response.status_code}: {response.text}")
except Exception as e:
mo.md(f"❌ Error: {e}")
else:
mo.md("*Type a message and click Send*")
return
if __name__ == "__main__":
app.run()