Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -884,16 +884,18 @@ HTML = """
|
|
884 |
|
885 |
<section id="home" class="fade-in">
|
886 |
<div class="upload-container">
|
887 |
-
<button
|
888 |
<i class="fas fa-images"></i> μ΄λ―Έμ§ μΆκ°
|
889 |
-
<input id="imgInput" type="file" accept="image/*" multiple hidden>
|
890 |
</button>
|
891 |
-
<button
|
892 |
<i class="fas fa-file-pdf"></i> PDF μΆκ°
|
893 |
-
<input id="pdfInput" type="file" accept="application/pdf" hidden>
|
894 |
</button>
|
895 |
</div>
|
896 |
|
|
|
|
|
|
|
|
|
897 |
<div class="section-title">λ΄ νλ‘μ νΈ</div>
|
898 |
<div class="grid" id="grid">
|
899 |
<!-- μΉ΄λκ° μ¬κΈ°μ λμ μΌλ‘ μΆκ°λ©λλ€ -->
|
@@ -926,54 +928,161 @@ HTML = """
|
|
926 |
.play().then(a=>a.pause()).catch(()=>{});document.removeEventListener(evt,u,{capture:true});},
|
927 |
{once:true,capture:true});
|
928 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
929 |
|
930 |
-
// μ
λ‘λ
|
931 |
-
function
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
941 |
}
|
942 |
-
}
|
|
|
943 |
});
|
944 |
}
|
945 |
-
|
946 |
-
/* ββ μ νΈ ββ */
|
947 |
-
function $id(id){return document.getElementById(id)}
|
948 |
|
949 |
-
//
|
950 |
-
function
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
961 |
}
|
|
|
962 |
|
963 |
-
//
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
console.log('PDF μ
λ‘λ λ²νΌ μ΄λ²€νΈ μ€μ ');
|
968 |
-
pdfBtn.onclick = function(e) {
|
969 |
-
e.preventDefault();
|
970 |
-
e.stopPropagation();
|
971 |
-
pdfInput.click();
|
972 |
-
};
|
973 |
}
|
|
|
|
|
974 |
}
|
975 |
-
|
976 |
-
function addCard(i, thumb, title, isCached = false) {
|
977 |
const d = document.createElement('div');
|
978 |
d.className = 'card fade-in';
|
979 |
d.onclick = () => open(i);
|
@@ -1000,53 +1109,8 @@ HTML = """
|
|
1000 |
$id('noProjects').style.display = 'none';
|
1001 |
}
|
1002 |
|
1003 |
-
/* ββ
|
1004 |
-
$id(
|
1005 |
-
const files=[...e.target.files]; if(!files.length) return;
|
1006 |
-
|
1007 |
-
// λ‘λ© νμ μΆκ°
|
1008 |
-
showLoading("μ΄λ―Έμ§ λ‘λ© μ€...");
|
1009 |
-
|
1010 |
-
const pages=[],tot=files.length;let done=0;
|
1011 |
-
files.forEach((f,i)=>{const r=new FileReader();r.onload=x=>{pages[i]={src:x.target.result,thumb:x.target.result};
|
1012 |
-
if(++done===tot) {
|
1013 |
-
save(pages, 'μ΄λ―Έμ§ 컬λ μ
');
|
1014 |
-
hideLoading();
|
1015 |
-
}
|
1016 |
-
};r.readAsDataURL(f);});
|
1017 |
-
};
|
1018 |
-
|
1019 |
-
/* ββ PDF μ
λ‘λ ββ */
|
1020 |
-
$id('pdfInput').onchange=e=>{
|
1021 |
-
const file=e.target.files[0]; if(!file) return;
|
1022 |
-
|
1023 |
-
// λ‘λ© νμ μΆκ°
|
1024 |
-
showLoading("PDF λ‘λ© μ€...");
|
1025 |
-
|
1026 |
-
const fr=new FileReader();
|
1027 |
-
fr.onload=v=>{
|
1028 |
-
pdfjsLib.getDocument({data:v.target.result}).promise.then(async pdf=>{
|
1029 |
-
const pages=[];
|
1030 |
-
|
1031 |
-
for(let p=1;p<=pdf.numPages;p++){
|
1032 |
-
// λ‘λ© μν μ
λ°μ΄νΈ
|
1033 |
-
updateLoading(`PDF νμ΄μ§ λ‘λ© μ€... (${p}/${pdf.numPages})`);
|
1034 |
-
|
1035 |
-
const pg=await pdf.getPage(p), vp=pg.getViewport({scale:1});
|
1036 |
-
const c=document.createElement('canvas');c.width=vp.width;c.height=vp.height;
|
1037 |
-
await pg.render({canvasContext:c.getContext('2d'),viewport:vp}).promise;
|
1038 |
-
pages.push({src:c.toDataURL(),thumb:c.toDataURL()});
|
1039 |
-
}
|
1040 |
-
|
1041 |
-
hideLoading();
|
1042 |
-
save(pages, file.name.replace('.pdf', ''));
|
1043 |
-
}).catch(error => {
|
1044 |
-
console.error("PDF λ‘λ© μ€λ₯:", error);
|
1045 |
-
hideLoading();
|
1046 |
-
showError("PDF λ‘λ© μ€ μ€λ₯κ° λ°μνμ΅λλ€.");
|
1047 |
-
});
|
1048 |
-
};fr.readAsArrayBuffer(file);
|
1049 |
-
};
|
1050 |
|
1051 |
/* ββ νλ‘μ νΈ μ μ₯ ββ */
|
1052 |
function save(pages, title, isCached = false){
|
@@ -1524,22 +1588,7 @@ HTML = """
|
|
1524 |
}
|
1525 |
|
1526 |
/* ββ λ€λΉκ²μ΄μ
ββ */
|
1527 |
-
|
1528 |
-
if(fb) {
|
1529 |
-
fb.destroy();
|
1530 |
-
viewer.innerHTML = '';
|
1531 |
-
fb = null;
|
1532 |
-
}
|
1533 |
-
toggle(true);
|
1534 |
-
|
1535 |
-
// λ‘λ© μΈλμΌμ΄ν° μ 리
|
1536 |
-
if (pageLoadingInterval) {
|
1537 |
-
clearInterval(pageLoadingInterval);
|
1538 |
-
pageLoadingInterval = null;
|
1539 |
-
}
|
1540 |
-
$id('loadingPages').style.display = 'none';
|
1541 |
-
currentLoadingPdfPath = null;
|
1542 |
-
};
|
1543 |
|
1544 |
function toggle(showHome){
|
1545 |
$id('home').style.display=showHome?'block':'none';
|
@@ -1642,16 +1691,7 @@ HTML = """
|
|
1642 |
}, 5000);
|
1643 |
}
|
1644 |
|
1645 |
-
|
1646 |
-
window.addEventListener('DOMContentLoaded', () => {
|
1647 |
-
// μ§μ μ΄λ²€νΈ 리μ€λ μ€μ (λ νμ€ν λ°©λ²)
|
1648 |
-
setupDirectEvents();
|
1649 |
-
|
1650 |
-
loadServerPDFs();
|
1651 |
-
|
1652 |
-
// μΊμ μνλ₯Ό μ£ΌκΈ°μ μΌλ‘ νμΈ (3μ΄λ§λ€)
|
1653 |
-
setInterval(checkCacheStatus, 3000);
|
1654 |
-
});
|
1655 |
</script>
|
1656 |
</body>
|
1657 |
</html>
|
|
|
884 |
|
885 |
<section id="home" class="fade-in">
|
886 |
<div class="upload-container">
|
887 |
+
<button type="button" id="imageUploadBtn" class="upload">
|
888 |
<i class="fas fa-images"></i> μ΄λ―Έμ§ μΆκ°
|
|
|
889 |
</button>
|
890 |
+
<button type="button" id="pdfUploadBtn" class="upload">
|
891 |
<i class="fas fa-file-pdf"></i> PDF μΆκ°
|
|
|
892 |
</button>
|
893 |
</div>
|
894 |
|
895 |
+
<!-- νμΌ μ
λ ₯ μμλ₯Ό λ²νΌ λ°μΌλ‘ μ΄λνμ¬ λ³λ λ°°μΉ -->
|
896 |
+
<input id="imgInput" type="file" accept="image/*" multiple style="display:none">
|
897 |
+
<input id="pdfInput" type="file" accept="application/pdf" style="display:none">
|
898 |
+
|
899 |
<div class="section-title">λ΄ νλ‘μ νΈ</div>
|
900 |
<div class="grid" id="grid">
|
901 |
<!-- μΉ΄λκ° μ¬κΈ°μ λμ μΌλ‘ μΆκ°λ©λλ€ -->
|
|
|
928 |
.play().then(a=>a.pause()).catch(()=>{});document.removeEventListener(evt,u,{capture:true});},
|
929 |
{once:true,capture:true});
|
930 |
});
|
931 |
+
|
932 |
+
// νμ΄μ§ λ‘λ μ μ΄λ²€νΈ μ€μ
|
933 |
+
document.addEventListener('DOMContentLoaded', function() {
|
934 |
+
console.log('DOM Content Loaded - μ΄λ²€νΈ μ€μ μμ');
|
935 |
+
|
936 |
+
// μ΄λ―Έμ§ μ
λ‘λ λ²νΌ μ΄λ²€νΈ
|
937 |
+
var imageUploadBtn = document.getElementById('imageUploadBtn');
|
938 |
+
var imgInput = document.getElementById('imgInput');
|
939 |
+
|
940 |
+
if (imageUploadBtn && imgInput) {
|
941 |
+
console.log('μ΄λ―Έμ§ μ
λ‘λ λ²νΌ λ°κ²¬');
|
942 |
+
imageUploadBtn.addEventListener('click', function() {
|
943 |
+
console.log('μ΄λ―Έμ§ μ
λ‘λ λ²νΌ ν΄λ¦λ¨');
|
944 |
+
imgInput.click();
|
945 |
+
});
|
946 |
+
} else {
|
947 |
+
console.error('μ΄λ―Έμ§ μ
λ‘λ λ²νΌ λλ μ
λ ₯ μμλ₯Ό μ°Ύμ μ μμ');
|
948 |
+
}
|
949 |
+
|
950 |
+
// PDF μ
λ‘λ λ²νΌ μ΄λ²€νΈ
|
951 |
+
var pdfUploadBtn = document.getElementById('pdfUploadBtn');
|
952 |
+
var pdfInput = document.getElementById('pdfInput');
|
953 |
+
|
954 |
+
if (pdfUploadBtn && pdfInput) {
|
955 |
+
console.log('PDF μ
λ‘λ λ²νΌ λ°κ²¬');
|
956 |
+
pdfUploadBtn.addEventListener('click', function() {
|
957 |
+
console.log('PDF μ
λ‘λ λ²νΌ ν΄λ¦λ¨');
|
958 |
+
pdfInput.click();
|
959 |
+
});
|
960 |
+
} else {
|
961 |
+
console.error('PDF μ
λ‘λ λ²νΌ λλ μ
λ ₯ μμλ₯Ό μ°Ύμ μ μμ');
|
962 |
+
}
|
963 |
+
|
964 |
+
console.log('PDF/μ΄λ―Έμ§ μ
λ ₯ νλ μ΄λ²€νΈ μ€μ ');
|
965 |
+
if (imgInput) {
|
966 |
+
imgInput.addEventListener('change', function(e) {
|
967 |
+
console.log('μ΄λ―Έμ§ μ
λ ₯ λ³κ²½ κ°μ§λ¨');
|
968 |
+
handleImageUpload(e);
|
969 |
+
});
|
970 |
+
}
|
971 |
+
|
972 |
+
if (pdfInput) {
|
973 |
+
pdfInput.addEventListener('change', function(e) {
|
974 |
+
console.log('PDF μ
λ ₯ λ³κ²½ κ°μ§λ¨');
|
975 |
+
handlePdfUpload(e);
|
976 |
+
});
|
977 |
+
}
|
978 |
+
|
979 |
+
// ν λ²νΌ μ΄λ²€νΈ μ€μ
|
980 |
+
var homeButton = document.getElementById('homeButton');
|
981 |
+
if (homeButton) {
|
982 |
+
homeButton.addEventListener('click', function() {
|
983 |
+
console.log('ν λ²νΌ ν΄λ¦λ¨');
|
984 |
+
homeButtonClicked();
|
985 |
+
});
|
986 |
+
}
|
987 |
+
|
988 |
+
// μλ²μμ PDF λ‘λ
|
989 |
+
loadServerPDFs();
|
990 |
+
|
991 |
+
// μΊμ μν μ£ΌκΈ°μ νμΈ
|
992 |
+
setInterval(checkCacheStatus, 3000);
|
993 |
+
});
|
994 |
|
995 |
+
// μ΄λ―Έμ§ μ
λ‘λ μ²λ¦¬ ν¨μ
|
996 |
+
function handleImageUpload(e) {
|
997 |
+
const files = Array.from(e.target.files);
|
998 |
+
if (!files.length) return;
|
999 |
+
|
1000 |
+
// λ‘λ© νμ μΆκ°
|
1001 |
+
showLoading("μ΄λ―Έμ§ λ‘λ© μ€...");
|
1002 |
+
|
1003 |
+
const pages = [];
|
1004 |
+
let done = 0;
|
1005 |
+
const total = files.length;
|
1006 |
+
|
1007 |
+
files.forEach((file, index) => {
|
1008 |
+
const reader = new FileReader();
|
1009 |
+
reader.onload = function(event) {
|
1010 |
+
pages[index] = {
|
1011 |
+
src: event.target.result,
|
1012 |
+
thumb: event.target.result
|
1013 |
+
};
|
1014 |
+
done++;
|
1015 |
+
if (done === total) {
|
1016 |
+
save(pages, 'μ΄λ―Έμ§ 컬λ μ
');
|
1017 |
+
hideLoading();
|
1018 |
}
|
1019 |
+
};
|
1020 |
+
reader.readAsDataURL(file);
|
1021 |
});
|
1022 |
}
|
|
|
|
|
|
|
1023 |
|
1024 |
+
// PDF μ
λ‘λ μ²λ¦¬ ν¨μ
|
1025 |
+
function handlePdfUpload(e) {
|
1026 |
+
const file = e.target.files[0];
|
1027 |
+
if (!file) return;
|
1028 |
+
|
1029 |
+
// λ‘λ© νμ μΆκ°
|
1030 |
+
showLoading("PDF λ‘λ© μ€...");
|
1031 |
+
|
1032 |
+
const reader = new FileReader();
|
1033 |
+
reader.onload = function(event) {
|
1034 |
+
pdfjsLib.getDocument({data: event.target.result}).promise.then(async pdf => {
|
1035 |
+
const pages = [];
|
1036 |
+
|
1037 |
+
for (let p = 1; p <= pdf.numPages; p++) {
|
1038 |
+
// λ‘λ© μν μ
λ°μ΄νΈ
|
1039 |
+
updateLoading(`PDF νμ΄μ§ λ‘λ© μ€... (${p}/${pdf.numPages})`);
|
1040 |
+
|
1041 |
+
const page = await pdf.getPage(p);
|
1042 |
+
const viewport = page.getViewport({scale: 1});
|
1043 |
+
const canvas = document.createElement('canvas');
|
1044 |
+
canvas.width = viewport.width;
|
1045 |
+
canvas.height = viewport.height;
|
1046 |
+
|
1047 |
+
await page.render({
|
1048 |
+
canvasContext: canvas.getContext('2d'),
|
1049 |
+
viewport: viewport
|
1050 |
+
}).promise;
|
1051 |
+
|
1052 |
+
pages.push({
|
1053 |
+
src: canvas.toDataURL(),
|
1054 |
+
thumb: canvas.toDataURL()
|
1055 |
+
});
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
hideLoading();
|
1059 |
+
save(pages, file.name.replace('.pdf', ''));
|
1060 |
+
}).catch(error => {
|
1061 |
+
console.error("PDF λ‘λ© μ€λ₯:", error);
|
1062 |
+
hideLoading();
|
1063 |
+
showError("PDF λ‘λ© μ€ μ€λ₯κ° λ°μνμ΅λλ€.");
|
1064 |
+
});
|
1065 |
+
};
|
1066 |
+
reader.readAsArrayBuffer(file);
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
// ν λ²νΌ ν΄λ¦ μ²λ¦¬ ν¨μ
|
1070 |
+
function homeButtonClicked() {
|
1071 |
+
if (fb) {
|
1072 |
+
fb.destroy();
|
1073 |
+
viewer.innerHTML = '';
|
1074 |
+
fb = null;
|
1075 |
}
|
1076 |
+
toggle(true);
|
1077 |
|
1078 |
+
// λ‘λ© μΈλμΌμ΄ν° μ 리
|
1079 |
+
if (pageLoadingInterval) {
|
1080 |
+
clearInterval(pageLoadingInterval);
|
1081 |
+
pageLoadingInterval = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
1082 |
}
|
1083 |
+
document.getElementById('loadingPages').style.display = 'none';
|
1084 |
+
currentLoadingPdfPath = null;
|
1085 |
}
|
|
|
|
|
1086 |
const d = document.createElement('div');
|
1087 |
d.className = 'card fade-in';
|
1088 |
d.onclick = () => open(i);
|
|
|
1109 |
$id('noProjects').style.display = 'none';
|
1110 |
}
|
1111 |
|
1112 |
+
/* ββ μ νΈ ββ */
|
1113 |
+
function $id(id){return document.getElementById(id)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1114 |
|
1115 |
/* ββ νλ‘μ νΈ μ μ₯ ββ */
|
1116 |
function save(pages, title, isCached = false){
|
|
|
1588 |
}
|
1589 |
|
1590 |
/* ββ λ€λΉκ²μ΄μ
ββ */
|
1591 |
+
$id('homeButton').onclick=homeButtonClicked;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1592 |
|
1593 |
function toggle(showHome){
|
1594 |
$id('home').style.display=showHome?'block':'none';
|
|
|
1691 |
}, 5000);
|
1692 |
}
|
1693 |
|
1694 |
+
function addCard(i, thumb, title, isCached = false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1695 |
</script>
|
1696 |
</body>
|
1697 |
</html>
|