cocoat commited on
Commit
3f8cbe4
·
verified ·
1 Parent(s): ece253e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -28
app.py CHANGED
@@ -101,31 +101,40 @@ def infer(
101
  history.insert(0, (img, caption_text))
102
  progress(1.0, desc="Done!")
103
 
104
- # Gallery dict リスト
105
  gallery_items = [
106
- {"image": item[0], "caption": make_html_table(item[1])}
107
  for item in history
108
  ]
109
  return img, gallery_items
110
 
111
- # CSS設定(温かい喫茶店風+カスタムローディング+モーダルオーバーレイ)
112
  css = """
113
  body { background-color:#f4e1c1; font-family:'Georgia', serif; }
114
- #col-container { background:#fffaf1; padding:20px; border-radius:16px;
115
- box-shadow:0 4px 12px rgba(0,0,0,0.1); margin:auto; max-width:780px; }
 
 
116
  /* リンク */
117
- #col-container a { color:#8b5e3c; text-decoration:none;
118
- border-bottom:1px dotted #8b5e3c; }
 
119
  /* カスタムローディング */
120
  .gradio-spinner { display:none !important; }
121
- #custom-loader { display:none; align-items:center; justify-content:center;
122
- font-weight:bold; margin:12px 0; }
 
 
123
  body.gradio-running #custom-loader { display:flex!important; }
124
- @keyframes fadeLetter {0%,100%{opacity:1;}50%{opacity:0.2;}}
125
- #custom-loader .loading-text span { display:inline-block;
126
- animation:fadeLetter 1s ease-in-out infinite; }
127
- #custom-loader img { width:32px; height:32px; border-radius:50%;
128
- margin-left:8px; }
 
 
 
 
129
  /* モーダルオーバーレイ */
130
  #modal-overlay {
131
  display:none; position:fixed; top:0; left:0; width:100vw; height:100vh;
@@ -143,6 +152,12 @@ body.gradio-running #custom-loader { display:flex!important; }
143
  }
144
  #modal-img { max-width:100%; max-height:60vh; display:block; margin:0 auto; }
145
  #modal-caption { margin-top:12px; }
 
 
 
 
 
 
146
  """
147
 
148
  with gr.Blocks(css=css) as demo:
@@ -150,12 +165,12 @@ with gr.Blocks(css=css) as demo:
150
  gr.Markdown("## SDXL Base – cocoamixXL3 Demo")
151
  gr.Markdown("[Link: Civitai](https://civitai.com/models/1553716?modelVersionId=1855218)")
152
 
153
- # フォーム
154
  with gr.Row():
155
  prompt = gr.Textbox(lines=1, placeholder="Prompt…",
156
  value="1girl, cocoart, masterpiece, anime,")
157
  neg = gr.Textbox(lines=1, placeholder="Negative prompt",
158
- value="low quality, worst quality,…")
159
  with gr.Row():
160
  seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
161
  rand = gr.Checkbox(True, label="Randomize seed")
@@ -178,19 +193,20 @@ with gr.Blocks(css=css) as demo:
178
  + ''.join(
179
  f'<span style="animation-delay:{i*0.1:.1f}s">{c}</span>'
180
  for i, c in enumerate("in progress")
181
- ) +
182
- '<img src="icon.png" alt="icon"/></div>'
183
  )
184
 
 
185
  img_out = gr.Image()
186
 
187
  # 生成履歴ギャラリー
188
  history_gallery = gr.Gallery(
189
  label="生成履歴", columns=4, height=280,
190
- show_label=False, interactive=True, type="auto"
191
  )
192
 
193
- # 自前モーダル HTML+スクリプト
194
  gr.HTML("""
195
  <div id="modal-overlay">
196
  <div id="modal-content">
@@ -200,17 +216,14 @@ with gr.Blocks(css=css) as demo:
200
  </div>
201
  </div>
202
  <script>
203
- document.addEventListener('click', (e) => {
204
- // サムネイル画像クリック
205
- if (e.target.closest('.gr-gallery img')) {
206
- const img = e.target.src;
207
- // figcaption 内の HTML を取得
208
- const cap = e.target.parentElement.querySelector('figcaption')?.innerHTML || '';
209
- document.getElementById('modal-img').src = img;
210
  document.getElementById('modal-caption').innerHTML = cap;
211
  document.getElementById('modal-overlay').style.display = 'flex';
212
  }
213
- // 閉じるボタン or オーバーレイ背景クリック
214
  if (e.target.id==='modal-close' || e.target.id==='modal-overlay') {
215
  document.getElementById('modal-overlay').style.display = 'none';
216
  }
 
101
  history.insert(0, (img, caption_text))
102
  progress(1.0, desc="Done!")
103
 
104
+ # Gallery 用に (PIL.Image, HTML) のタプルリスト
105
  gallery_items = [
106
+ (item[0], make_html_table(item[1]))
107
  for item in history
108
  ]
109
  return img, gallery_items
110
 
111
+ # CSS設定(温かい喫茶店風+カスタムローディング+モーダル)
112
  css = """
113
  body { background-color:#f4e1c1; font-family:'Georgia', serif; }
114
+ #col-container {
115
+ background:#fffaf1; padding:20px; border-radius:16px;
116
+ box-shadow:0 4px 12px rgba(0,0,0,0.1); margin:auto; max-width:780px;
117
+ }
118
  /* リンク */
119
+ #col-container a {
120
+ color:#8b5e3c; text-decoration:none; border-bottom:1px dotted #8b5e3c;
121
+ }
122
  /* カスタムローディング */
123
  .gradio-spinner { display:none !important; }
124
+ #custom-loader {
125
+ display:none; align-items:center; justify-content:center;
126
+ font-weight:bold; margin:12px 0;
127
+ }
128
  body.gradio-running #custom-loader { display:flex!important; }
129
+ @keyframes fadeLetter { 0%,100%{opacity:1;} 50%{opacity:0.2;} }
130
+ #custom-loader .loading-text span {
131
+ display:inline-block; animation:fadeLetter 1s ease-in-out infinite;
132
+ }
133
+ #custom-loader img {
134
+ width:32px; height:32px; border-radius:50%; margin-left:8px;
135
+ }
136
+ /* Gallery */
137
+ .gr-gallery { background:#fffaf1; padding:10px; border-radius:12px; }
138
  /* モーダルオーバーレイ */
139
  #modal-overlay {
140
  display:none; position:fixed; top:0; left:0; width:100vw; height:100vh;
 
152
  }
153
  #modal-img { max-width:100%; max-height:60vh; display:block; margin:0 auto; }
154
  #modal-caption { margin-top:12px; }
155
+ /* デフォルトのローディング要素を完全に非表示に */
156
+ .loading-screen,
157
+ .gradio-container > .loading,
158
+ .gradio-container .loading {
159
+ display: none !important;
160
+ }
161
  """
162
 
163
  with gr.Blocks(css=css) as demo:
 
165
  gr.Markdown("## SDXL Base – cocoamixXL3 Demo")
166
  gr.Markdown("[Link: Civitai](https://civitai.com/models/1553716?modelVersionId=1855218)")
167
 
168
+ # フォーム配置
169
  with gr.Row():
170
  prompt = gr.Textbox(lines=1, placeholder="Prompt…",
171
  value="1girl, cocoart, masterpiece, anime,")
172
  neg = gr.Textbox(lines=1, placeholder="Negative prompt",
173
+ value="low quality, worst quality, …")
174
  with gr.Row():
175
  seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
176
  rand = gr.Checkbox(True, label="Randomize seed")
 
193
  + ''.join(
194
  f'<span style="animation-delay:{i*0.1:.1f}s">{c}</span>'
195
  for i, c in enumerate("in progress")
196
+ )
197
+ + '<img src="icon.png" alt="icon"/></div>'
198
  )
199
 
200
+ # 生成プレビュー
201
  img_out = gr.Image()
202
 
203
  # 生成履歴ギャラリー
204
  history_gallery = gr.Gallery(
205
  label="生成履歴", columns=4, height=280,
206
+ show_label=False, interactive=True, type="pil"
207
  )
208
 
209
+ # 自前モーダル HTML + JS
210
  gr.HTML("""
211
  <div id="modal-overlay">
212
  <div id="modal-content">
 
216
  </div>
217
  </div>
218
  <script>
219
+ document.addEventListener('click', e => {
220
+ const thumb = e.target.closest('.gr-gallery img');
221
+ if (thumb) {
222
+ document.getElementById('modal-img').src = thumb.src;
223
+ const cap = thumb.closest('figure').querySelector('figcaption')?.innerHTML || '';
 
 
224
  document.getElementById('modal-caption').innerHTML = cap;
225
  document.getElementById('modal-overlay').style.display = 'flex';
226
  }
 
227
  if (e.target.id==='modal-close' || e.target.id==='modal-overlay') {
228
  document.getElementById('modal-overlay').style.display = 'none';
229
  }