Download License from Phupingbut1989/Deploy-Auto: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/datasets/Phupingbut1989/Deploy-Auto/resolve/main/License
- Command line
-
hf download hf://datasets/Phupingbut1989/Deploy-Auto/License
-
curl -L -o License https://huggingface.co/datasets/Phupingbut1989/Deploy-Auto/resolve/main/License
3.42 kB
| --- | |
| # 📄 ไฟล์ที่ 2: main.py | |
| ```python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| 🌐 CRISTAL AI — Deploy-Auto Main Application | |
| TPS Group · Genai | |
| Version: 1.0.0 | |
| """ | |
| from fastapi import FastAPI, Request, Form | |
| from fastapi.responses import HTMLResponse, JSONResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from pathlib import Path | |
| import os | |
| # ========================================== | |
| # ✅ สร้างแอปพลิเคชัน — สำคัญ: ต้องมาก่อนใช้งาน! | |
| # ========================================== | |
| BASE_DIR = Path(__file__).resolve().parent | |
| app = FastAPI( | |
| title="Cristal AI", | |
| version="1.0.0", | |
| description="Cristal is the creator of world-class AI" | |
| ) | |
| # ========================================== | |
| # 📁 ตั้งค่าโฟลเดอร์ไฟล์ | |
| # ========================================== | |
| try: | |
| app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static") | |
| except Exception: | |
| pass | |
| templates = Jinja2Templates(directory=str(BASE_DIR / "templates")) | |
| # ========================================== | |
| # 🌐 หน้าเว็บ — Public Routes | |
| # ========================================== | |
| def home(request: Request): | |
| return templates.TemplateResponse(request, "index.html", {"page": "home"}) | |
| def signup_page(request: Request): | |
| return templates.TemplateResponse(request, "signup.html", {"page": "signup"}) | |
| def login_page(request: Request): | |
| return templates.TemplateResponse(request, "login.html", {"page": "login"}) | |
| def chat_page(request: Request): | |
| return templates.TemplateResponse(request, "chat.html", {"page": "chat"}) | |
| # ========================================== | |
| # 💬 API Endpoints | |
| # ========================================== | |
| def chat_send(message: str = Form(...)): | |
| return { | |
| "success": True, | |
| "reply": f"Cristal: คุณพูดว่า — '{message}' 🤖✨", | |
| "provider": "demo", | |
| "version": "1.0.0" | |
| } | |
| def api_status(): | |
| return { | |
| "status": "online", | |
| "name": "Cristal AI", | |
| "version": "1.0.0", | |
| "deploy": "Deploy-Auto ✅", | |
| "owner": "TPS Group" | |
| } | |
| # ========================================== | |
| # 🔧 เครื่องมือเพิ่ม API ได้เอง | |
| # ========================================== | |
| def add_api(method: str, path: str, handler): | |
| """ | |
| เพิ่ม API ใหม่ได้ง่ายๆ | |
| ตัวอย่าง: add_api("GET", "/hello", lambda: {"msg": "สวัสดี"}) | |
| """ | |
| if method.upper() == "GET": | |
| app.get(path)(handler) | |
| elif method.upper() == "POST": | |
| app.post(path)(handler) | |
| # ตัวอย่างการใช้งาน | |
| # add_api("GET", "/hello", lambda: {"message": "สวัสดีจาก Cristal AI!"}) | |
| # ========================================== | |
| # ✅ รันเซิร์ฟเวอร์ | |
| # ========================================== | |
| if __name__ == "__main__": | |
| import uvicorn | |
| port = int(os.getenv("PORT", 8080)) | |
| uvicorn.run(app, host="0.0.0.0", port=port) | |