# -*- coding: utf-8 -*- """ ================================================== 🚀 DEPLOY-AUTO — Cristal AI All-in-One File เวอร์ชัน: 1.0.0 เจ้าของ: TPS Group · Thanwa Phupingbut (Rufio D'noto) ใช้งาน: รันไฟล์นี้ได้เลย หรือ Deploy บน Railway, Vercel, Render, Hang ฯลฯ ================================================== """ 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 import sys # ========================================== # ✅ สร้างแอป — สำคัญที่สุด ต้องมาก่อน! # ========================================== BASE_DIR = Path(__file__).resolve().parent app = FastAPI( title="Cristal AI", version="1.0.0", description="Cristal is the creator of world-class AI" ) # ========================================== # 📁 สร้างโฟลเดอร์และไฟล์อัตโนมัติ # ========================================== def ensure_folders(): """สร้างโฟลเดอร์ที่จำเป็นถ้ายังไม่มี""" folders = [ BASE_DIR / "templates", BASE_DIR / "static" / "css", BASE_DIR / "static" / "js" ] for f in folders: f.mkdir(parents=True, exist_ok=True) ensure_folders() # ========================================== # 📝 เนื้อหาไฟล์หน้าเว็บ — ฝังในโค้ดเลย # ========================================== FILES = { "templates/base.html": """ {% block title %}Cristal AI{% endblock %}
{% block content %}{% endblock %}
""", "templates/index.html": """{% extends "base.html" %} {% block title %}Cristal AI — ปัญญาประดิษฐ์ระดับโลก{% endblock %} {% block content %}

Cristal คือผู้สร้าง
ปัญญาประดิษฐ์ระดับโลก

ออกแบบเทคโนโลยี การสนทนา และอนาคตของ AI ไปพร้อมกับคุณ

{% endblock %}""", "templates/signup.html": """{% extends "base.html" %} {% block title %}สมัครสมาชิก · Cristal AI{% endblock %} {% block content %}

สร้างบัญชี Cristal

เข้าร่วมระบบ AI ระดับโลก

มีบัญชีอยู่แล้ว? เข้าสู่ระบบ

{% endblock %}""", "templates/login.html": """{% extends "base.html" %} {% block title %}เข้าสู่ระบบ · Cristal AI{% endblock %} {% block content %}

ยินดีต้อนรับกลับมา

เข้าสู่ระบบเพื่อใช้งาน Cristal AI

ยังไม่มีบัญชี? สมัครใช้งาน

{% endblock %}""", "templates/chat.html": """{% extends "base.html" %} {% block title %}พูดคุย · Cristal AI{% endblock %} {% block content %}

🤖 Cristal AI — พร้อมช่วยเหลือ

🤖
สวัสดีครับ! ผมคือ Cristal AI ✨
พิมพ์ข้อความด้านล่างเพื่อคุยกับผมได้เลยครับ
{% endblock %}""", "static/css/style.css": """* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; } body { background: #0f0f1a; color: #fff; min-height: 100vh; } .navbar { background: #12121f; border-bottom: 1px solid #2a2a3f; padding: 1rem 2rem; position: sticky; top: 0; } .nav-container { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; } .logo { font-size: 1.3rem; font-weight: 700; color: #fff; text-decoration: none; } .nav-menu a { color: #b0b0c0; text-decoration: none; margin: 0 0.8rem; } .nav-menu a:hover, .nav-menu a.active { color: #8b5cf6; } .nav-actions a { text-decoration: none; padding: 0.6rem 1.2rem; border-radius: 8px; margin-left: 0.5rem; } .btn-login { color: #fff; border: 1px solid transparent; } .btn-login:hover { border-color: #444; } .btn-signup { background: #8b5cf6; color: #fff; font-weight: 500; } .hero { max-width: 800px; margin: 6rem auto; text-align: center; padding: 2rem; } .hero h1 { font-size: 3rem; line-height: 1.2; margin-bottom: 1.5rem; } .hero h1 span { background: linear-gradient(135deg, #8b5cf6, #d946ef); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .hero p { font-size: 1.2rem; color: #9ca3af; margin-bottom: 2.5rem; } .hero-buttons a { display: inline-block; padding: 1rem 2rem; border-radius: 10px; text-decoration: none; font-weight: 600; margin: 0 0.5rem; } .btn-primary { background: #8b5cf6; color: white; border: none; cursor: pointer; transition: transform 0.2s; } .btn-primary:hover { transform: translateY(-2px); } .btn-secondary { background: #1f1f2e; color: white; border: 1px solid #333; } .auth-section { max-width: 420px; margin: 4rem auto; padding: 2rem; } .auth-card h1 { font-size: 1.8rem; margin-bottom: 0.5rem; } .auth-card p { color: #9ca3af; margin-bottom: 2rem; } .auth-form input { width: 100%; padding: 0.9rem 1rem; margin-bottom: 1rem; background: #1f1f2e; border: 1px solid #333; border-radius: 8px; color: #fff; font-size: 1rem; outline: none; } .auth-form input:focus { border-color: #8b5cf6; } .full-width { width: 100%; } .auth-switch { text-align: center; margin-top: 1.5rem; color: #9ca3af; } .auth-switch a { color: #8b5cf6; text-decoration: none; } .chat-container { max-width: 700px; margin: 2rem auto; padding: 0 1rem; } .chat-box { background: #12121f; border-radius: 16px; border: 1px solid #2a2a3f; overflow: hidden; } .chat-header { padding: 1.2rem 1.5rem; border-bottom: 1px solid #2a2a3f; } .chat-header h2 { font-size: 1.1rem; } .chat-messages { height: 450px; overflow-y: auto; padding: 1.5rem; background: #0f0f1a; } .ai-message, .user-message { display: flex; margin-bottom: 1.2rem; gap: 0.8rem; } .user-message { flex-direction: row-reverse; } .ai-avatar { font-size: 1.8rem; flex-shrink: 0; } .message-bubble { background: #1f1f2e; padding: 0.9rem 1.2rem; border-radius: 12px; line-height: 1.5; max-width: 80%; } .user-bubble { background: #8b5cf6; } .chat-input { display: flex; gap: 0.8rem; padding: 1.2rem; border-top: 1px solid #2a2a3f; } .chat-input input { flex: 1; padding: 0.9rem 1.2rem; background: #1f1f2e; border: 1px solid #333; border-radius: 8px; color: #fff; font-size: 1rem; outline: none; } .chat-input input:focus { border-color: #8b5cf6; } .footer { text-align: center; padding: 2rem; color: #6b7280; font-size: 0.9rem; border-top: 1px solid #2a2a3f; margin-top: 4rem; } @media(max-width: 640px) { .hero h1 { font-size: 2rem; } .nav-container { justify-content: center; text-align: center; } .nav-menu { width: 100%; margin: 0.5rem 0; } }""", "static/js/main.js": """console.log("✨ Cristal AI System Loaded"); """ } # ========================================== # 💾 เขียนไฟล์อัตโนมัติเมื่อรันครั้งแรก # ========================================== def write_files(): """สร้างไฟล์หน้าเว็บอัตโนมัติ""" for path, content in FILES.items(): file_path = BASE_DIR / path if not file_path.exists(): file_path.write_text(content, encoding="utf-8") print(f"✅ สร้างไฟล์: {path}") write_files() # ตั้งค่า templates templates = Jinja2Templates(directory=str(BASE_DIR / "templates")) # ========================================== # 🌐 หน้าเว็บ # ========================================== @app.get("/", response_class=HTMLResponse) def home(request: Request): return templates.TemplateResponse(request, "index.html", {"page": "home"}) @app.get("/signup", response_class=HTMLResponse) def signup_page(request: Request): return templates.TemplateResponse(request, "signup.html", {"page": "signup"}) @app.get("/login", response_class=HTMLResponse) def login_page(request: Request): return templates.TemplateResponse(request, "login.html", {"page": "login"}) @app.get("/chat", response_class=HTMLResponse) def chat_page(request: Request): return templates.TemplateResponse(request, "chat.html", {"page": "chat"}) # ========================================== # 💬 API # ========================================== @app.post("/api/chat/send") def chat_send(message: str = Form(...)): return { "success": True, "reply": f"Cristal: คุณพูดว่า — '{message}' 🤖✨\nระบบทำงานปกติแล้วครับ! ✅", "version": "1.0.0" } @app.get("/api/status") def api_status(): return { "status": "online", "name": "Cristal AI", "version": "1.0.0", "deploy": "Deploy-Auto ✅", "note": "All-in-One Single File — Ready to Deploy" } # ========================================== # ✅ รันเซิร์ฟเวอร์ # ========================================== if __name__ == "__main__": import uvicorn port = int(os.getenv("PORT", 8080)) print(f"\n🚀 ========================================") print(f"✨ Cristal AI กำลังทำงานแล้วครับ!") print(f"🌐 เปิดที่: http://localhost:{port}") print(f"📖 API Status: http://localhost:{port}/api/status") print(f"🚀 Deploy-Auto — Ready to Deploy") print(f"=========================================\n") uvicorn.run(app, host="0.0.0.0", port=port)