Skip to content

Commit

Permalink
✨ add Freak.stop method
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgafni committed Nov 7, 2023
1 parent 9eee3eb commit b608c81
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ curl -X 'PATCH' \

Because Freak is using `FastAPI`, it's possible to use auto-generated documentation to interact with the Freak server. The interactive documentation can be accessed at Freak's main endpoint, which by default is `localhost:4444`.

The following screenshot shows the generated endpoints for the ML [example](https://github.com/danielgafni/freak/blob/master/examples/dl_example.py). Warning: making ML pipelines less reproducible isn't the brightest idea!
The following screenshot shows the generated endpoints for the ML [example](https://github.com/danielgafni/freak/blob/master/examples/dl_example.py). Warning: making ML pipelines less reproducible isn't the brightest idea! But it's convenient to use Freak for stopping a training.

![Sample Generated Docs](https://raw.githubusercontent.com/danielgafni/freak/master/resources/swagger.png)

Expand Down
11 changes: 9 additions & 2 deletions freak/freak.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,26 @@ def control(self, state: T, serve: bool = True):
self.serve()

def serve(self):
server = UvicornServer(
self.server = UvicornServer(
config=Config(app=self.app, host=self.host, port=self.port, log_level=self.uvicorn_log_level)
)
server.run_in_thread()
self.server.run_in_thread()
# logger.info(f"Running Freak on http://{self.host}:{self.port}")

def stop(self):
self.server.cleanup()

def add_routes(self, app: FastAPI, state: T) -> FastAPI:
init_state = state.copy(deep=True)

router = APIRouter(prefix=self.prefix)

state_name = state.__repr_name__()

@router.post("/stop", description=f"Stop the Freak server", tags=["stop"])
async def stop_server(): # pyright: ignore
self.stop()

@router.get("/get", description=f"Get the whole {state_name}", tags=[state_name])
async def get_state() -> type(state): # pyright: ignore
return state
Expand Down
Loading

0 comments on commit b608c81

Please sign in to comment.