Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,108 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
def noop(): return None
|
| 4 |
|
| 5 |
with gr.Blocks() as demo:
|
| 6 |
-
#
|
| 7 |
gr.HTML("""
|
| 8 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
/* モーダルオーバーレイ */
|
| 10 |
-
#modal-overlay {
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
</style>
|
|
|
|
|
|
|
| 14 |
<div id="modal-overlay">
|
| 15 |
<div id="modal-content">
|
| 16 |
-
<
|
| 17 |
-
<
|
|
|
|
| 18 |
</div>
|
| 19 |
</div>
|
|
|
|
| 20 |
<script>
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
document.getElementById('modal-overlay').style.display = 'none';
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
</script>
|
| 28 |
-
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
btn = gr.Button("モーダルを開く", elem_id="open-modal")
|
| 32 |
|
| 33 |
-
demo.
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
# 以下省略:torch/pipe 定義などは既存コードをそのまま使ってください
|
|
|
|
| 3 |
|
| 4 |
with gr.Blocks() as demo:
|
| 5 |
+
# ─── ここからインラインで CSS+JS ───
|
| 6 |
gr.HTML("""
|
| 7 |
<style>
|
| 8 |
+
/* デフォルトのローディングを完全に隠す */
|
| 9 |
+
.loading-screen, .gradio-container > .loading, .gradio-container .loading {
|
| 10 |
+
display: none !important;
|
| 11 |
+
}
|
| 12 |
+
/* カスタムローダー */
|
| 13 |
+
#custom-loader {
|
| 14 |
+
display: none;
|
| 15 |
+
align-items: center;
|
| 16 |
+
justify-content: center;
|
| 17 |
+
font-weight: bold;
|
| 18 |
+
margin: 12px 0;
|
| 19 |
+
}
|
| 20 |
+
body.gradio-running #custom-loader {
|
| 21 |
+
display: flex !important;
|
| 22 |
+
}
|
| 23 |
+
@keyframes fadeLetter { 0%,100%{opacity:1;}50%{opacity:0.2;} }
|
| 24 |
+
#custom-loader span {
|
| 25 |
+
display: inline-block;
|
| 26 |
+
animation: fadeLetter 1s ease-in-out infinite;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
/* モーダルオーバーレイ */
|
| 30 |
+
#modal-overlay {
|
| 31 |
+
display: none;
|
| 32 |
+
position: fixed;
|
| 33 |
+
top: 0; left: 0;
|
| 34 |
+
width: 100vw; height: 100vh;
|
| 35 |
+
background: rgba(0,0,0,0.6);
|
| 36 |
+
align-items: center; justify-content: center;
|
| 37 |
+
z-index: 9999;
|
| 38 |
+
}
|
| 39 |
+
#modal-content {
|
| 40 |
+
background: white;
|
| 41 |
+
padding: 20px;
|
| 42 |
+
border-radius: 8px;
|
| 43 |
+
max-width: 80vw; max-height: 80vh;
|
| 44 |
+
overflow: auto;
|
| 45 |
+
position: relative;
|
| 46 |
+
}
|
| 47 |
+
#modal-close {
|
| 48 |
+
position: absolute; top:8px; right:8px;
|
| 49 |
+
background: #c48f61; color: white; border: none;
|
| 50 |
+
width: 32px; height: 32px; border-radius: 50%;
|
| 51 |
+
cursor: pointer;
|
| 52 |
+
}
|
| 53 |
+
#modal-img { max-width:100%; max-height:60vh; display:block; margin:0 auto; }
|
| 54 |
+
#modal-caption { margin-top:12px; }
|
| 55 |
</style>
|
| 56 |
+
|
| 57 |
+
<!-- モーダル構造 -->
|
| 58 |
<div id="modal-overlay">
|
| 59 |
<div id="modal-content">
|
| 60 |
+
<button id="modal-close">×</button>
|
| 61 |
+
<img id="modal-img" src="" alt="expanded"/>
|
| 62 |
+
<div id="modal-caption"></div>
|
| 63 |
</div>
|
| 64 |
</div>
|
| 65 |
+
|
| 66 |
<script>
|
| 67 |
+
document.addEventListener('click', e => {
|
| 68 |
+
const t = e.target;
|
| 69 |
+
// モーダルを閉じる
|
| 70 |
+
if (t.id==='modal-close' || t.id==='modal-overlay') {
|
| 71 |
document.getElementById('modal-overlay').style.display = 'none';
|
| 72 |
+
return;
|
| 73 |
+
}
|
| 74 |
+
// ギャラリーサムネイルをクリック
|
| 75 |
+
const thumb = t.closest('.gr-gallery img');
|
| 76 |
+
if (thumb) {
|
| 77 |
+
document.getElementById('modal-img').src = thumb.src;
|
| 78 |
+
const cap = thumb.closest('figure').querySelector('figcaption')?.innerHTML || '';
|
| 79 |
+
document.getElementById('modal-caption').innerHTML = cap;
|
| 80 |
+
document.getElementById('modal-overlay').style.display = 'flex';
|
| 81 |
+
}
|
| 82 |
+
});
|
| 83 |
</script>
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
# ─── ここまで ───
|
| 87 |
+
|
| 88 |
+
# 以下、既存の UI 定義に続きます
|
| 89 |
+
with gr.Column(elem_id="col-container"):
|
| 90 |
+
gr.Markdown("## SDXL Base – cocoamixXL3 Demo")
|
| 91 |
+
gr.Markdown("[Link: Civitai](https://civitai.com/models/1553716?modelVersionId=1855218)")
|
| 92 |
+
|
| 93 |
+
gr.HTML(
|
| 94 |
+
'<div id="custom-loader">'
|
| 95 |
+
+ ''.join(
|
| 96 |
+
f'<span style="animation-delay:{i*0.1:.1f}s">{c}</span>'
|
| 97 |
+
for i, c in enumerate("in progress")
|
| 98 |
+
)
|
| 99 |
+
+ '<img src="/icon.png" style="width:32px;height:32px;border-radius:50%;margin-left:8px;"/>'
|
| 100 |
+
+ '</div>'
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# …(フォーム、ボタン、Gallery)…
|
| 104 |
|
| 105 |
+
# run.click と demo.launch() もそのまま
|
|
|
|
| 106 |
|
| 107 |
+
demo.queue()
|
| 108 |
+
demo.launch()
|