Skip to content

Commit

Permalink
Merge pull request #104 from 1chooo/ho-dev
Browse files Browse the repository at this point in the history
separate main, Refinaid.App
  • Loading branch information
1chooo authored Sep 8, 2023
2 parents 3f9b659 + 16a1b26 commit dd1fc82
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 83 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- [Website](https://gradio.app) -->
<!-- | [Guides](https://gradio.app/guides/) -->
Expand Down
82 changes: 82 additions & 0 deletions Refinaid/App/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
11 changes: 9 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo "venv has been activated"
else
source venv/bin/activate
echo "venv is activated"
fi

python main.py
89 changes: 10 additions & 79 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit dd1fc82

Please sign in to comment.