File size: 750 Bytes
9f65c03
37e7757
9f65c03
37e7757
9f65c03
 
 
 
37e7757
9f65c03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---

# 3. 📄 Dummy Specialized AI (Space: ActualDummyAI)

app.py:
```python
from fastapi import FastAPI, WebSocket
import asyncio, json

app = FastAPI()

@app.websocket("/ws/dummy")
async def ws_dummy(ws: WebSocket):
    await ws.accept()
    await ws.send_json({"type":"ready","msg":"Dummy AI online"})
    try:
        async for msg in ws.iter_text():
            data = json.loads(msg)
            # pretend to process step by step
            for i in range(3):
                await asyncio.sleep(1)
                await ws.send_json({"type":"step","text":f"Step {i+1} for task: {data}"})
            await ws.send_json({"type":"done","result":f"Finished task: {data}"})
    except Exception as e:
        await ws.send_json({"error":str(e)})