diff --git a/README.md b/README.md index 402d9c9..7f0cf35 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ [![Made with Python](https://img.shields.io/pypi/pyversions/gradio.svg?color=blue)](https://python.org "Go to Python homepage") [![License](https://img.shields.io/badge/License-MIT-blue)](./LICENSE "Go to license section") -[Documentation](1chooo.github.io/simple-ai/) -| [中文](readme_files/zh-cn#readme) +[Documentation](https://github.com/1chooo/simple-ai) +| [中文](readme_files/zh_cn#readme) diff --git a/Refinaid/App/app.py b/Refinaid/App/app.py index 140bee6..5185dec 100644 --- a/Refinaid/App/app.py +++ b/Refinaid/App/app.py @@ -3,3 +3,85 @@ Author: @1chooo (Hugo ChunHo Lin) Version: v0.1.1 ''' + +import os +from fastapi import FastAPI, Request +from fastapi.templating import Jinja2Templates +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi import Form, Depends, HTTPException +import gradio as gr +from Refinaid.gui.Launch import build_ui + +PLAYGROUND_PATH = "/gradio" + +app = FastAPI( + title="SIMPLE AI", + description="Bridging the Gap with AI For Everyone", + version="0.1.2", + docs_url="/docs", +) + +os.makedirs("static", exist_ok=True) +app.mount("/static", StaticFiles(directory="static"), name="static") + +templates = Jinja2Templates(directory="templates") + +demo = build_ui() +app = gr.mount_gradio_app( + app, demo, path=PLAYGROUND_PATH +) + +@app.get("/", response_class=HTMLResponse) +async def page_overview(request: Request): + return templates.TemplateResponse( + "index.html", {"request": request} + ) + +@app.get("/project_docs", response_class=HTMLResponse) +async def page_project_docs(request: Request): + return templates.TemplateResponse( + "docs.html", {"request": request} + ) + +@app.get("/login", response_class=HTMLResponse) +async def page_login(request: Request, ): + return templates.TemplateResponse( + f"login.html", {"request": request} + ) + +@app.get("/setting", response_class=HTMLResponse) +async def page_setting(request: Request, ): + return templates.TemplateResponse( + f"setting.html", {"request": request} + ) + +@app.get("/signup", response_class=HTMLResponse) +async def page_signup(request: Request, ): + return templates.TemplateResponse( + f"signup.html", {"request": request} + ) + +@app.get("/help", response_class=HTMLResponse) +async def page_help(request: Request, ): + return templates.TemplateResponse( + f"help.html", {"request": request} + ) + +@app.get("/settings", response_class=HTMLResponse) +async def page_settings(request: Request, ): + return templates.TemplateResponse( + f"settings.html", {"request": request} + ) + +@app.get("/orders", response_class=HTMLResponse) +async def page_orders(request: Request, ): + return templates.TemplateResponse( + f"orders.html", {"request": request} + ) + +@app.get("/playgrounds", response_class=HTMLResponse) +async def page_orders(request: Request, ): + return templates.TemplateResponse( + f"playgrounds.html", {"request": request} + ) diff --git a/build.sh b/build.sh index 11649c1..a164ac4 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,14 @@ #!/bin/zsh -# Version v0.1.1 +# Version v0.1.2 # Author: Hugo ChunHo Lin # GitHub: github.com/1chooo # Copyright (C) 2023 Hugo ChunHo Lin All rights reserved. -uvicorn main:app --host 127.0.0.1 --port 5002 --reload \ No newline at end of file +if [[ "$VIRTUAL_ENV" != "" ]]; then + echo "venv has been activated" +else + source venv/bin/activate + echo "venv is activated" +fi + +python main.py diff --git a/main.py b/main.py index 53f9754..2167e73 100644 --- a/main.py +++ b/main.py @@ -2,87 +2,18 @@ Create Date: 2023/08/25 Author: @VincentLi1216, @1chooo Email: sunnus.tw@gmail.com -Version: v0.1.1 +Version: v0.1.2 ''' -import os -from fastapi import FastAPI, Request -from fastapi.templating import Jinja2Templates -from fastapi.responses import HTMLResponse -from fastapi.staticfiles import StaticFiles -from fastapi import Form, Depends, HTTPException -import gradio as gr -from Refinaid.gui.Launch import build_ui +import uvicorn -PLAYGROUND_PATH = "/gradio" - -app = FastAPI() - -os.makedirs("static", exist_ok=True) -app.mount("/static", StaticFiles(directory="static"), name="static") - -templates = Jinja2Templates(directory="templates") - -demo = build_ui() -app = gr.mount_gradio_app( - app, demo, path=PLAYGROUND_PATH -) - -@app.get("/", response_class=HTMLResponse) -async def page_overview(request: Request): - return templates.TemplateResponse( - "index.html", {"request": request} - ) - -@app.get("/project_docs", response_class=HTMLResponse) -async def page_project_docs(request: Request): - return templates.TemplateResponse( - "docs.html", {"request": request} - ) - -@app.get("/login", response_class=HTMLResponse) -async def page_login(request: Request, ): - return templates.TemplateResponse( - f"login.html", {"request": request} - ) - -@app.get("/setting", response_class=HTMLResponse) -async def page_setting(request: Request, ): - return templates.TemplateResponse( - f"setting.html", {"request": request} +def main() -> None: + uvicorn.run( + app="Refinaid.App.app:app", + host="127.0.0.1", + port=5002, + reload=True, ) -@app.get("/signup", response_class=HTMLResponse) -async def page_signup(request: Request, ): - return templates.TemplateResponse( - f"signup.html", {"request": request} - ) - -@app.get("/help", response_class=HTMLResponse) -async def page_help(request: Request, ): - return templates.TemplateResponse( - f"help.html", {"request": request} - ) - -@app.get("/settings", response_class=HTMLResponse) -async def page_settings(request: Request, ): - return templates.TemplateResponse( - f"settings.html", {"request": request} - ) - -@app.get("/orders", response_class=HTMLResponse) -async def page_orders(request: Request, ): - return templates.TemplateResponse( - f"orders.html", {"request": request} - ) - -@app.get("/playgrounds", response_class=HTMLResponse) -async def page_orders(request: Request, ): - return templates.TemplateResponse( - f"playgrounds.html", {"request": request} - ) - - -# if __name__ == '__main__': -# import uvicorn -# uvicorn.run(app, host="127.0.0.1", port=5002) +if __name__ == '__main__': + main()