🤗pyにKISSして🤗

あか(aka7774)によるAI関連のpython成果物に対する提言です!

KISSの原則 (*´з`)


問題意識

あるべき姿

実装テンプレート

app.py

import fn
import gradio as gr

fn.load_model()

with gr.Blocks() as demo:
    # UI here

if __name__ == '__main__':
    demo.launch()

main.py

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

import fn
import gradio as gr
from app import demo

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

gr.mount_gradio_app(app, demo, path="/gradio")

fn.load_model()

@app.post("/sample")
async def api_sample(args: dict):
    return {}

fn.py

def load_model():
  pass

def run():
  pass

venv.sh

#!/usr/bin/bash

python3 -m venv venv
curl -kL https://bootstrap.pypa.io/get-pip.py | venv/bin/python

venv/bin/python -m pip install gradio
venv/bin/python -m pip install -r requirements.txt

requirements.txt

fastapi
uvicorn

README.md

sdk: gradio
sdk_version: 4.20.0
app_file: app.py

ホーム