Yuchan5386 commited on
Commit
f2dad0f
·
verified ·
1 Parent(s): 9c75ab6

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +14 -0
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")