Spaces:
Sleeping
Sleeping
Create api.py
Browse files
api.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import StreamingResponse
|
3 |
+
import time
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
def stream_text():
|
8 |
+
for word in ["안녕", "세상아", "나는", "스트리밍", "API야", "!"]:
|
9 |
+
yield f"{word} "
|
10 |
+
time.sleep(0.5)
|
11 |
+
|
12 |
+
@app.get("/stream")
|
13 |
+
def stream():
|
14 |
+
return StreamingResponse(stream_text(), media_type="text/plain")
|