Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
# app.py
|
|
|
|
|
|
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.responses import HTMLResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -8,70 +11,114 @@ BASE = pathlib.Path(__file__).parent
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
| 12 |
app.mount("/static", StaticFiles(directory=BASE), name="static")
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
| 15 |
INDEX_HTML = """
|
| 16 |
<!DOCTYPE html>
|
| 17 |
<html lang="ko">
|
| 18 |
<head>
|
| 19 |
<meta charset="UTF-8">
|
| 20 |
<title>FlipBook β μ
λ‘λ + μ¬μ΄λ</title>
|
|
|
|
| 21 |
<link rel="stylesheet" href="/static/flipbook.css">
|
|
|
|
|
|
|
| 22 |
<script src="/static/three.js"></script>
|
| 23 |
<script src="/static/iscroll.js"></script>
|
| 24 |
<script src="/static/mark.js"></script>
|
| 25 |
<script src="/static/mod3d.js"></script>
|
|
|
|
| 26 |
<script src="/static/flipbook.js"></script>
|
| 27 |
<script src="/static/flipbook.book3.js"></script>
|
| 28 |
<script src="/static/flipbook.scroll.js"></script>
|
| 29 |
<script src="/static/flipbook.swipe.js"></script>
|
| 30 |
<script src="/static/flipbook.webgl.js"></script>
|
|
|
|
| 31 |
<style>
|
| 32 |
body{margin:0;font-family:sans-serif;background:#f4f4f4}
|
| 33 |
-
|
|
|
|
| 34 |
.upload-wrapper{display:flex;justify-content:center}
|
| 35 |
-
#uploadBtn{
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
#fileInput{display:none}
|
| 38 |
</style>
|
| 39 |
</head>
|
| 40 |
<body>
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
<div id="viewer"></div>
|
|
|
|
| 43 |
<div class="upload-wrapper">
|
| 44 |
<button id="uploadBtn" title="μ΄λ―Έμ§ μ
λ‘λ">π·</button>
|
| 45 |
<input id="fileInput" type="file" accept="image/*" multiple>
|
| 46 |
</div>
|
|
|
|
| 47 |
<script>
|
| 48 |
-
let book=null
|
|
|
|
|
|
|
| 49 |
document.getElementById('uploadBtn').onclick=()=>document.getElementById('fileInput').click();
|
|
|
|
| 50 |
document.getElementById('fileInput').onchange=e=>{
|
| 51 |
if(!e.target.files.length) return;
|
| 52 |
-
const files=[...e.target.files]
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
};
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
book=
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
controlsProps:{enableFullscreen:true,thumbnails:true}
|
| 64 |
});
|
| 65 |
}
|
| 66 |
</script>
|
| 67 |
-
</body
|
|
|
|
| 68 |
"""
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
@app.get("/", response_class=HTMLResponse)
|
| 71 |
async def root():
|
| 72 |
return INDEX_HTML
|
| 73 |
|
| 74 |
-
#
|
|
|
|
|
|
|
| 75 |
if __name__ == "__main__":
|
| 76 |
port = int(os.environ.get("PORT", 7860))
|
| 77 |
uvicorn.run("app:app", host="0.0.0.0", port=port, reload=False)
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
# FastAPI μλ² + Real3D FlipBook μ μ μ¬μ΄νΈ
|
| 3 |
+
# λͺ¨λ μ μ νμΌ(JS / CSS / MP3 / μ΄λ―Έμ§ λ±)κ³Ό μ΄ νμΌμ κ°μ ν΄λμ λ‘λλ€.
|
| 4 |
+
|
| 5 |
from fastapi import FastAPI
|
| 6 |
from fastapi.responses import HTMLResponse
|
| 7 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 15 |
+
# 1) /static β νμ¬ ν΄λ(λΌμ΄λΈλ¬λ¦¬Β·MP3Β·μ΄λ―Έμ§) μλΉ
|
| 16 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 17 |
app.mount("/static", StaticFiles(directory=BASE), name="static")
|
| 18 |
|
| 19 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 20 |
+
# 2) index.html μλ¬Έ (μ€λμ€ κ²½λ‘ /static/turnPage2.mp3 λ‘ μμ )
|
| 21 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 22 |
INDEX_HTML = """
|
| 23 |
<!DOCTYPE html>
|
| 24 |
<html lang="ko">
|
| 25 |
<head>
|
| 26 |
<meta charset="UTF-8">
|
| 27 |
<title>FlipBook β μ
λ‘λ + μ¬μ΄λ</title>
|
| 28 |
+
|
| 29 |
<link rel="stylesheet" href="/static/flipbook.css">
|
| 30 |
+
|
| 31 |
+
<!-- νμ JS μμ -->
|
| 32 |
<script src="/static/three.js"></script>
|
| 33 |
<script src="/static/iscroll.js"></script>
|
| 34 |
<script src="/static/mark.js"></script>
|
| 35 |
<script src="/static/mod3d.js"></script>
|
| 36 |
+
|
| 37 |
<script src="/static/flipbook.js"></script>
|
| 38 |
<script src="/static/flipbook.book3.js"></script>
|
| 39 |
<script src="/static/flipbook.scroll.js"></script>
|
| 40 |
<script src="/static/flipbook.swipe.js"></script>
|
| 41 |
<script src="/static/flipbook.webgl.js"></script>
|
| 42 |
+
|
| 43 |
<style>
|
| 44 |
body{margin:0;font-family:sans-serif;background:#f4f4f4}
|
| 45 |
+
h2{text-align:center;margin:24px 0}
|
| 46 |
+
#viewer{width:900px;height:600px;margin:0 auto 40px;background:#fff;border:1px solid #ccc}
|
| 47 |
.upload-wrapper{display:flex;justify-content:center}
|
| 48 |
+
#uploadBtn{
|
| 49 |
+
all:unset;width:44px;height:44px;line-height:44px;text-align:center;
|
| 50 |
+
font-size:26px;border-radius:50%;cursor:pointer;
|
| 51 |
+
background:#ffb84d;color:#fff;box-shadow:0 2px 4px rgba(0,0,0,.2);
|
| 52 |
+
}
|
| 53 |
#fileInput{display:none}
|
| 54 |
</style>
|
| 55 |
</head>
|
| 56 |
<body>
|
| 57 |
+
|
| 58 |
+
<h2>Real3D FlipBook β μ΄λ―Έμ§ μ
λ‘λ π·β¨</h2>
|
| 59 |
+
|
| 60 |
<div id="viewer"></div>
|
| 61 |
+
|
| 62 |
<div class="upload-wrapper">
|
| 63 |
<button id="uploadBtn" title="μ΄λ―Έμ§ μ
λ‘λ">π·</button>
|
| 64 |
<input id="fileInput" type="file" accept="image/*" multiple>
|
| 65 |
</div>
|
| 66 |
+
|
| 67 |
<script>
|
| 68 |
+
let book=null;
|
| 69 |
+
const viewer=document.getElementById('viewer');
|
| 70 |
+
|
| 71 |
document.getElementById('uploadBtn').onclick=()=>document.getElementById('fileInput').click();
|
| 72 |
+
|
| 73 |
document.getElementById('fileInput').onchange=e=>{
|
| 74 |
if(!e.target.files.length) return;
|
| 75 |
+
const files=[...e.target.files];
|
| 76 |
+
const pages=[], tot=files.length; let read=0;
|
| 77 |
+
files.forEach((f,i)=>{
|
| 78 |
+
const r=new FileReader();
|
| 79 |
+
r.onload=ev=>{
|
| 80 |
+
pages[i]={src:ev.target.result,thumb:ev.target.result};
|
| 81 |
+
if(++read===tot) createBook(pages);
|
| 82 |
+
};
|
| 83 |
+
r.readAsDataURL(f);
|
| 84 |
+
});
|
| 85 |
};
|
| 86 |
+
|
| 87 |
+
function createBook(pages){
|
| 88 |
+
if(book){ book.destroy(); viewer.innerHTML=''; }
|
| 89 |
+
|
| 90 |
+
book=new FlipBook(viewer,{
|
| 91 |
+
pages,
|
| 92 |
+
viewMode:'webgl',
|
| 93 |
+
autoSize:true,
|
| 94 |
+
flipDuration:800,
|
| 95 |
+
backgroundColor:'#ffffff',
|
| 96 |
+
|
| 97 |
+
/* π μ¬μ΄λ β μ μ κ²½λ‘ μ§μ */
|
| 98 |
+
sound:true,
|
| 99 |
+
assets:{
|
| 100 |
+
flipMp3 : '/static/turnPage2.mp3',
|
| 101 |
+
hardFlipMp3 : '/static/turnPage2.mp3'
|
| 102 |
+
},
|
| 103 |
+
|
| 104 |
controlsProps:{enableFullscreen:true,thumbnails:true}
|
| 105 |
});
|
| 106 |
}
|
| 107 |
</script>
|
| 108 |
+
</body>
|
| 109 |
+
</html>
|
| 110 |
"""
|
| 111 |
|
| 112 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 113 |
+
# 3) λ£¨νΈ κ²½λ‘ β index.html λ°ν
|
| 114 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 115 |
@app.get("/", response_class=HTMLResponse)
|
| 116 |
async def root():
|
| 117 |
return INDEX_HTML
|
| 118 |
|
| 119 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 120 |
+
# 4) Hugging Face Spacesκ° python app.py λ‘ μ€ν μ μλ² κΈ°λ
|
| 121 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 122 |
if __name__ == "__main__":
|
| 123 |
port = int(os.environ.get("PORT", 7860))
|
| 124 |
uvicorn.run("app:app", host="0.0.0.0", port=port, reload=False)
|