File size: 1,412 Bytes
ca0a0ff
 
 
 
 
 
 
 
3379bc9
ca0a0ff
 
b73eed5
 
 
9d7a35f
2f9ca82
043470a
9d7a35f
b73eed5
2c3dd0c
2f9ca82
 
9d7a35f
b73eed5
2f9ca82
 
 
 
 
 
 
 
 
 
 
 
 
2c3dd0c
9d7a35f
 
2c3dd0c
 
b73eed5
2f9ca82
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# agent/notebook.py

import os
import sys
import threading
import uvicorn
import asyncio

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
process_name = os.path.splitext(os.path.basename(__file__))[0]

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from agents.notebook.auth import router as auth_router
from agents.notebook.views import router as notebook_router
from tools.storage import Storage

app = FastAPI()

app.mount("/static", StaticFiles(directory=os.path.join(os.path.dirname(__file__), "notebook/static")), name="static")
templates = Jinja2Templates(directory=os.path.join(os.path.dirname(__file__), "notebook/templates"))

app.include_router(auth_router)
app.include_router(notebook_router)

@app.on_event("startup")
async def start_heartbeat():
    asyncio.create_task(heartbeat_loop())

async def heartbeat_loop():
    while True:
        storage.update_heartbeat(process_name)
        if storage.check_stop_flag(process_name):
            print("⛔ Получен сигнал остановки.")
            break
        await asyncio.sleep(60)

def run_notebook(host: str = "127.0.0.1", port: int = 8000):
    uvicorn.run(app, host=host, port=port)

if __name__ == "__main__":
    print("[*] Запуск пользовательского интерфейса...")
    run_notebook()