Spaces:
Build error
Build error
Download app.py from hguddn/ajou_chatbot_api: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/spaces/hguddn/ajou_chatbot_api/resolve/main/app.py
- Command line
-
hf download hf://spaces/hguddn/ajou_chatbot_api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hguddn/ajou_chatbot_api/resolve/main/app.py
716 Bytes
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from src.llama_Qwen2 import ask_qwen2 | |
| app = FastAPI() | |
| # 보안 에러(CORS) 방지 | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # 실제 배포 시에는 GitLab Pages 주소만 넣는 것이 안전합니다. | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| class ChatRequest(BaseModel): | |
| message: str | |
| async def chat_endpoint(request: ChatRequest): | |
| user_input = request.message | |
| output_response = ask_qwen2(user_input) | |
| return {"reply": output_response} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |