Spaces:
Sleeping
Sleeping
| # /// script | |
| # requires-python = ">=3.10" | |
| # dependencies = [ | |
| # "marimo", | |
| # "requests", | |
| # ] | |
| # /// | |
| import marimo | |
| __generated_with = "0.9.0" | |
| app = marimo.App() | |
| def _(): | |
| import marimo as mo | |
| import requests | |
| return mo, requests | |
| def _(mo): | |
| mo.md("# π¦ VerdantClaw Chat") | |
| mo.md("**Simple chat with ZeroClaw**") | |
| mo.md("---") | |
| return | |
| 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 | |
| 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() | |