Download server.py from abancp/10M-LLM: direct link, hf CLI and curl.
- Browser
- Download file 589 Bytes
-
https://huggingface.co/spaces/abancp/10M-LLM/resolve/main/server.py
- Command line
-
hf download hf://spaces/abancp/10M-LLM/server.py
-
curl -L -o server.py https://huggingface.co/spaces/abancp/10M-LLM/resolve/main/server.py
589 Bytes
| from fastapi import FastAPI, Request | |
| from fastapi.responses import StreamingResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from inference import generate_response | |
| import time | |
| app = FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:5173"], # your React app's port | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def chat(req: Request): | |
| body = await req.json() | |
| prompt = body.get("prompt") | |
| return StreamingResponse(generate_response(prompt), media_type="text/plain") | |