File size: 523 Bytes
4c3aac8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import time
from collections.abc import Generator
from fastapi.responses import HTMLResponse
from gradio import Server
demo = Server()
@demo.api()
def stream(message: str) -> Generator[str, None, None]:
full = ""
for word in ["Hello", " ", "world", "!"]:
full += word
yield full
time.sleep(0.1)
@demo.get("/", response_class=HTMLResponse)
async def homepage():
with open("client.html", encoding="utf-8") as f:
return f.read()
if __name__ == "__main__":
demo.launch()
|