Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
current_command = None
|
| 6 |
+
|
| 7 |
+
class Command(BaseModel):
|
| 8 |
+
action: str
|
| 9 |
+
x: int
|
| 10 |
+
y: int
|
| 11 |
+
|
| 12 |
+
@app.post("/send-command")
|
| 13 |
+
async def send_command(command: Command):
|
| 14 |
+
global current_command
|
| 15 |
+
current_command = command
|
| 16 |
+
return {"status": "command_received"}
|
| 17 |
+
|
| 18 |
+
@app.get("/get-command")
|
| 19 |
+
async def get_command():
|
| 20 |
+
return current_command
|
| 21 |
+
|
| 22 |
+
if __name__ == '__main__':
|
| 23 |
+
import uvicorn
|
| 24 |
+
uvicorn.run(app, host='0.0.0.0', port=8000)
|