Spaces:
Running
on
Zero
Running
on
Zero
import os | |
from django.core.asgi import get_asgi_application | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.templating import Jinja2Templates | |
from starlette.middleware.cors import CORSMiddleware | |
import logging | |
import gradio as gr | |
from gradio_config import setup_gradio_interfaces | |
from webhook import setup_webhook_routes | |
from database import setup_database_routes | |
from asgi_config import init_django_app | |
# ロガーの設定 | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
file_handler = logging.FileHandler("app.log") | |
file_handler.setLevel(logging.INFO) | |
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | |
file_handler.setFormatter(formatter) | |
logger.addHandler(file_handler) | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") | |
application = get_asgi_application() | |
app = FastAPI() | |
# Djangoアプリケーションの初期化 | |
init_django_app(app, application) | |
# ミドルウェアの設定 | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Gradioインターフェースの設定 | |
gradio_interfaces = setup_gradio_interfaces() | |
# Webhookルートの設定 | |
setup_webhook_routes(app) | |
# データベースルートの設定 | |
setup_database_routes(app) | |
# Gradioアプリのマウント | |
app.mount("/static", StaticFiles(directory="static", html=True), name="static") | |
app = gr.mount_gradio_app(app, gradio_interfaces, "/") | |
# テンプレートファイルが格納されているディレクトリを指定 | |
templates = Jinja2Templates(directory="static") | |
def get_some_page(request: Request): | |
return templates.TemplateResponse("index.html", {"request": request}) | |
def hello_world(): | |
return "Hello World" | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=7860) | |