Spaces:
Runtime error
Runtime error
Commit
·
8f2f662
1
Parent(s):
0e6d5fd
Fixing dockerfile v8
Browse files- src/api.py +11 -11
src/api.py
CHANGED
|
@@ -27,17 +27,17 @@ class InferenceApi(LitAPI):
|
|
| 27 |
)
|
| 28 |
self.logger.info(f"Inference API setup completed on device: {device}")
|
| 29 |
|
| 30 |
-
async def predict(self, x: str, **kwargs) -> Union[str, Iterator[str]]:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
def decode_request(self, request: Any, **kwargs) -> str:
|
| 43 |
"""Convert the request payload to input format."""
|
|
|
|
| 27 |
)
|
| 28 |
self.logger.info(f"Inference API setup completed on device: {device}")
|
| 29 |
|
| 30 |
+
async def predict(self, x: str, **kwargs) -> Union[str, Iterator[str]]:
|
| 31 |
+
"""
|
| 32 |
+
Main prediction method required by LitAPI.
|
| 33 |
+
If streaming is enabled, yields chunks; otherwise returns via yield.
|
| 34 |
+
"""
|
| 35 |
+
if self.stream:
|
| 36 |
+
async for chunk in self.generate_stream(x, **kwargs):
|
| 37 |
+
yield chunk
|
| 38 |
+
else:
|
| 39 |
+
response = await self.generate_response(x, **kwargs)
|
| 40 |
+
yield response
|
| 41 |
|
| 42 |
def decode_request(self, request: Any, **kwargs) -> str:
|
| 43 |
"""Convert the request payload to input format."""
|