-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: restore client.py file (#28)
* restore client * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add client test * remove mdformat * Update README.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test run * assert generated * run server from cmd * reformat comment * remove generate client test * increase sleep --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Aniket Maurya <[email protected]>
- Loading branch information
1 parent
2a47331
commit 01aabe1
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import requests | ||
|
||
response = requests.post("http://127.0.0.1:8000/predict", json={"input": 4.0}) | ||
print(f"Status: {response.status_code}\nResponse:\n {response.text}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from litserve.server import LitServer | ||
from litserve.api import LitAPI | ||
from fastapi import Request, Response | ||
|
||
|
||
class SimpleLitAPI(LitAPI): | ||
def setup(self, device): | ||
self.model = lambda x: x**2 | ||
|
||
def decode_request(self, request: Request): | ||
return request["input"] | ||
|
||
def predict(self, x): | ||
return self.model(x) | ||
|
||
def encode_response(self, output) -> Response: | ||
return {"output": output} | ||
|
||
|
||
if __name__ == "__main__": | ||
server = LitServer(SimpleLitAPI(), accelerator="cpu", devices=1, timeout=10) | ||
server.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters