Spaces:
Sleeping
Sleeping
Kimilhee
commited on
Commit
·
ad5173e
1
Parent(s):
f8b00cc
Revert "vercel 배포판"
Browse filesThis reverts commit f8b00cc379cb443bfacb638012050b3bec1f3eef.
- .gitignore +0 -1
- api/index.py +0 -55
- main.py +58 -3
- vercel.json +0 -15
.gitignore
CHANGED
@@ -64,4 +64,3 @@ coverage.xml
|
|
64 |
local_settings.py
|
65 |
db.sqlite3
|
66 |
db.sqlite3-journal
|
67 |
-
.vercel
|
|
|
64 |
local_settings.py
|
65 |
db.sqlite3
|
66 |
db.sqlite3-journal
|
|
api/index.py
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI, Request
|
2 |
-
from fastapi.responses import HTMLResponse
|
3 |
-
from fastapi.staticfiles import StaticFiles
|
4 |
-
from fastapi.middleware.cors import CORSMiddleware
|
5 |
-
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
6 |
-
from fastapi import Depends, HTTPException, status
|
7 |
-
import gradio as gr
|
8 |
-
from app import setup_demo
|
9 |
-
import os
|
10 |
-
import secrets
|
11 |
-
|
12 |
-
app = FastAPI()
|
13 |
-
security = HTTPBasic()
|
14 |
-
|
15 |
-
|
16 |
-
# 인증 설정
|
17 |
-
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
|
18 |
-
correct_username = "daekyo"
|
19 |
-
correct_password = os.environ.get("DEFAULT_PW")
|
20 |
-
|
21 |
-
is_correct_username = secrets.compare_digest(credentials.username, correct_username)
|
22 |
-
is_correct_password = secrets.compare_digest(credentials.password, correct_password)
|
23 |
-
|
24 |
-
if not (is_correct_username and is_correct_password):
|
25 |
-
raise HTTPException(
|
26 |
-
status_code=status.HTTP_401_UNAUTHORIZED,
|
27 |
-
detail="Incorrect username or password",
|
28 |
-
headers={"WWW-Authenticate": "Basic"},
|
29 |
-
)
|
30 |
-
return credentials.username
|
31 |
-
|
32 |
-
|
33 |
-
# CORS 설정
|
34 |
-
app.add_middleware(
|
35 |
-
CORSMiddleware,
|
36 |
-
allow_origins=["*"],
|
37 |
-
allow_credentials=True,
|
38 |
-
allow_methods=["*"],
|
39 |
-
allow_headers=["*"],
|
40 |
-
)
|
41 |
-
|
42 |
-
# 정적 파일 서빙 설정
|
43 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
44 |
-
|
45 |
-
# Gradio 인터페이스 생성
|
46 |
-
demo = setup_demo()
|
47 |
-
app = gr.mount_gradio_app(
|
48 |
-
app, demo, path="/", auth=("daekyo", os.environ.get("DEFAULT_PW"))
|
49 |
-
)
|
50 |
-
|
51 |
-
|
52 |
-
# 메인 라우트
|
53 |
-
@app.get("/", response_class=HTMLResponse)
|
54 |
-
async def root(request: Request, username: str = Depends(get_current_username)):
|
55 |
-
return await demo.render_template(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
@@ -1,5 +1,60 @@
|
|
1 |
-
import
|
2 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
if __name__ == "__main__":
|
5 |
-
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
5 |
+
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
6 |
+
from fastapi import Depends, HTTPException, status
|
7 |
+
import gradio as gr
|
8 |
+
from app import setup_demo
|
9 |
+
import os
|
10 |
+
import secrets
|
11 |
+
|
12 |
+
app = FastAPI()
|
13 |
+
security = HTTPBasic()
|
14 |
+
|
15 |
+
|
16 |
+
# 인증 설정
|
17 |
+
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
|
18 |
+
correct_username = "daekyo"
|
19 |
+
correct_password = os.environ.get("DEFAULT_PW")
|
20 |
+
|
21 |
+
is_correct_username = secrets.compare_digest(credentials.username, correct_username)
|
22 |
+
is_correct_password = secrets.compare_digest(credentials.password, correct_password)
|
23 |
+
|
24 |
+
if not (is_correct_username and is_correct_password):
|
25 |
+
raise HTTPException(
|
26 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
27 |
+
detail="Incorrect username or password",
|
28 |
+
headers={"WWW-Authenticate": "Basic"},
|
29 |
+
)
|
30 |
+
return credentials.username
|
31 |
+
|
32 |
+
|
33 |
+
# CORS 설정
|
34 |
+
app.add_middleware(
|
35 |
+
CORSMiddleware,
|
36 |
+
allow_origins=["*"],
|
37 |
+
allow_credentials=True,
|
38 |
+
allow_methods=["*"],
|
39 |
+
allow_headers=["*"],
|
40 |
+
)
|
41 |
+
|
42 |
+
# 정적 파일 서빙 설정
|
43 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
44 |
+
|
45 |
+
# Gradio 인터페이스 생성
|
46 |
+
demo = setup_demo()
|
47 |
+
app = gr.mount_gradio_app(
|
48 |
+
app, demo, path="/", auth=("daekyo", os.environ.get("DEFAULT_PW"))
|
49 |
+
)
|
50 |
+
|
51 |
+
|
52 |
+
# 메인 라우트
|
53 |
+
@app.get("/", response_class=HTMLResponse)
|
54 |
+
async def root(request: Request, username: str = Depends(get_current_username)):
|
55 |
+
return await demo.render_template(request)
|
56 |
+
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
+
print("To run the server, use:")
|
60 |
+
print("uvicorn main:app --host 0.0.0.0 --port 8000 --reload")
|
vercel.json
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": 2,
|
3 |
-
"builds": [
|
4 |
-
{
|
5 |
-
"src": "api/index.py",
|
6 |
-
"use": "@vercel/python"
|
7 |
-
}
|
8 |
-
],
|
9 |
-
"routes": [
|
10 |
-
{
|
11 |
-
"src": "/(.*)",
|
12 |
-
"dest": "api/index.py"
|
13 |
-
}
|
14 |
-
]
|
15 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|