HAL1993 commited on
Commit
00125e3
·
verified ·
1 Parent(s): e178755

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -82
app.py CHANGED
@@ -25,6 +25,7 @@ logger = logging.getLogger(__name__)
25
 
26
  @spaces.GPU
27
  def translate_albanian_to_english(text: str, language: str = "en"):
 
28
  if not text.strip():
29
  raise gr.Error("Please enter a description.")
30
  for attempt in range(2):
@@ -92,6 +93,7 @@ QUALITY_PROMPT = ", high quality, detailed, vibrant, professional lighting"
92
 
93
  @spaces.GPU(duration=40)
94
  def infer(image, prompt):
 
95
  negative_prompt = ""
96
  seed = random.randint(0, MAX_SEED)
97
  generator = torch.Generator(device=device).manual_seed(seed)
@@ -131,7 +133,6 @@ def create_demo():
131
  @keyframes glow-hover {0%{box-shadow:0 0 20px rgba(0,255,128,0.7);}50%{box-shadow:0 0 20px rgba(0,255,128,0.9);}100%{box-shadow:0 0 20px rgba(0,255,128,0.7);}}
132
  @keyframes slide {0%{background-position:0% 50%;}50%{background-position:100% 50%;}100%{background-position:0% 50%;}}
133
  @keyframes pulse {0%,100%{opacity:0.7;}50%{opacity:1;}}
134
- @keyframes typewriter {0%{width:0;}100%{width:100%;}}
135
  body{
136
  background:#000000 !important;
137
  color:#FFFFFF !important;
@@ -178,7 +179,7 @@ def create_demo():
178
  background:#000000 !important;
179
  border:none !important;
180
  border-radius:8px;
181
- padding:0.5rem !important; /* reduced side padding for full width */
182
  box-shadow:0 0 10px rgba(255,255,255,0.3) !important;
183
  width:100% !important;
184
  max-width:100vw !important;
@@ -191,7 +192,7 @@ def create_demo():
191
  text-align:center;
192
  color:#FFFFFF !important;
193
  text-shadow:0 0 8px rgba(255,255,255,0.3) !important;
194
- margin:0 auto .5rem auto;
195
  display:block;
196
  max-width:100%;
197
  }
@@ -207,7 +208,7 @@ def create_demo():
207
  .gradio-component{
208
  background:#000000 !important;
209
  border:none;
210
- margin:0.25rem 0 !important; /* tighter vertical spacing */
211
  width:100% !important;
212
  max-width:100vw !important;
213
  color:#FFFFFF !important;
@@ -225,9 +226,8 @@ def create_demo():
225
  box-shadow:0 0 10px rgba(255,255,255,0.3) !important;
226
  position:relative;
227
  color:#FFFFFF !important;
228
- overflow:hidden !important;
229
  }
230
- .image-container img,.image-container video{
231
  width:100% !important;
232
  height:auto;
233
  box-sizing:border-box !important;
@@ -290,11 +290,10 @@ def create_demo():
290
  .image-container[aria-label="Result Image"].processing *{
291
  display:none !important;
292
  }
293
- .image-container[aria-label="Result Image"].processing video,
294
  .image-container[aria-label="Result Image"].processing img{
295
  display:none !important;
296
  }
297
- input,textarea,.gr-dropdown,.gr-dropdown select{
298
  background:#000000 !important;
299
  color:#FFFFFF !important;
300
  border:1px solid #FFFFFF !important;
@@ -304,7 +303,7 @@ def create_demo():
304
  max-width:100vw !important;
305
  box-sizing:border-box !important;
306
  }
307
- input:hover,textarea:hover,.gr-dropdown:hover,.gr-dropdown select:hover{
308
  box-shadow:0 0 8px rgba(255,255,255,0.3) !important;
309
  transition:box-shadow 0.3s;
310
  }
@@ -333,20 +332,8 @@ def create_demo():
333
  button[aria-label="Fullscreen"],button[aria-label="Share"],button[aria-label="Download"]{
334
  display:none !important;
335
  }
336
- button[aria-label="Download"]{
337
- transform:scale(3);
338
- transform-origin:top right;
339
- background:#000000 !important;
340
- color:#FFFFFF !important;
341
- border:1px solid #FFFFFF !important;
342
- border-radius:4px;
343
- padding:0.4rem !important;
344
- margin:0.5rem !important;
345
- box-shadow:0 0 8px rgba(255,255,255,0.3) !important;
346
- transition:box-shadow 0.3s;
347
- }
348
- button[aria-label="Download"]:hover{
349
- box-shadow:0 0 12px rgba(255,255,255,0.5) !important;
350
  }
351
  footer,.gr-button-secondary{
352
  display:none !important;
@@ -363,9 +350,12 @@ def create_demo():
363
  .gr-button-primary{
364
  padding:0.6rem 1rem;
365
  font-size:1rem;
 
 
366
  }
367
  .image-container{
368
  min-height:300px;
 
369
  }
370
  .image-container[aria-label="Result Image"].processing::before{
371
  font-size:1.2rem !important;
@@ -379,63 +369,29 @@ def create_demo():
379
  throw new Error('500');
380
  }
381
  document.addEventListener('DOMContentLoaded', () => {
382
- const forceHideGradioProcessing = () => {
383
- const selectors = [
384
- '.progress-text', '.gr-progress', '.gr-progress-bar', '.progress-bar',
385
- '[data-testid="progress"]', '.status', '.loading', '.spinner', '.gr-spinner',
386
- '.gr-loading', '.gr-status', '.gpu-init', '.initializing', '.queue',
387
- '.queued', '.waiting', '.processing', '.gradio-progress', '.gradio-status',
388
- 'div[class*="progress"]', 'div[class*="loading"]', 'div[class*="status"]',
389
- 'div[class*="spinner"]', '*[class*="progress"]', '*[class*="loading"]',
390
- '*[class*="status"]', '*[class*="spinner"]'
391
- ];
392
- selectors.forEach(selector => {
393
- document.querySelectorAll(selector).forEach(el => {
394
- el.style.display = 'none !important';
395
- el.style.visibility = 'hidden !important';
396
- el.style.opacity = '0 !important';
397
- el.style.height = '0 !important';
398
- el.style.width = '0 !important';
399
- el.style.position = 'absolute !important';
400
- el.style.left = '-9999px !important';
401
- el.style.top = '-9999px !important';
402
- el.style.zIndex = '-9999 !important';
403
  });
404
  });
405
- };
406
- forceHideGradioProcessing();
407
- const observer = new MutationObserver(forceHideGradioProcessing);
408
- observer.observe(document.body, { childList: true, subtree: true });
409
- const generateButton = document.querySelector('.gr-button-primary');
410
- const outputContainer = document.querySelector('.image-container[aria-label="Generated Video"]');
411
- if (generateButton && outputContainer) {
412
- generateButton.addEventListener('click', () => {
413
- outputContainer.classList.add('processing');
414
- const allChildren = outputContainer.querySelectorAll('*');
415
- allChildren.forEach(child => {
416
- if (child.tagName !== 'VIDEO' && child.tagName !== 'IMG') {
417
- child.style.display = 'none !important';
418
- }
419
  });
420
  });
421
- const videoObserver = new MutationObserver((mutations) => {
422
- mutations.forEach((mutation) => {
423
- if (mutation.addedNodes.length > 0) {
424
- mutation.addedNodes.forEach((node) => {
425
- if (node.nodeType === 1 && (node.tagName === 'VIDEO' || node.querySelector('video'))) {
426
- outputContainer.classList.remove('processing');
427
- videoObserver.disconnect();
428
- }
429
- });
430
- }
431
- });
432
- });
433
- videoObserver.observe(outputContainer, { childList: true, subtree: true });
434
  }
435
  setInterval(() => {
436
- forceHideGradioProcessing();
437
- const processingEls = document.querySelectorAll('.progress-text, .gr-progress, [class*="progress"]');
438
- processingEls.forEach(el => el.remove());
439
  }, 500);
440
  });
441
  </script>
@@ -452,17 +408,17 @@ def create_demo():
452
  show_download_button=False,
453
  show_share_button=False,
454
  interactive=True,
455
- elem_classes=["gradio-component", "image-container"]
456
  )
457
  prompt = gr.Textbox(
458
  label="Prompt",
459
  lines=3,
460
- elem_classes=["gradio-component"]
461
  )
462
  run_button = gr.Button(
463
  "Edit!",
464
  variant="primary",
465
- elem_classes=["gradio-component", "gr-button-primary"]
466
  )
467
  result_image = gr.Image(
468
  label="Result Image",
@@ -470,7 +426,7 @@ def create_demo():
470
  interactive=False,
471
  show_download_button=True,
472
  show_share_button=False,
473
- elem_classes=["gradio-component", "image-container"]
474
  )
475
  run_button.click(fn=infer, inputs=[input_image, prompt], outputs=[result_image])
476
  prompt.submit(fn=infer, inputs=[input_image, prompt], outputs=[result_image])
@@ -478,10 +434,7 @@ def create_demo():
478
 
479
  app = FastAPI()
480
  demo = create_demo()
481
- app.mount(
482
- "/y7u8i9o0p1l2k3j4h5g6f7d8s9a0q1w2e3r4t5y6u7i8o9p0l1k2j3h4g5f6d7s8",
483
- demo.app,
484
- )
485
 
486
  @app.get("/{path:path}")
487
  async def catch_all(path: str):
 
25
 
26
  @spaces.GPU
27
  def translate_albanian_to_english(text: str, language: str = "en"):
28
+ """Translate Albanian text to English using an external HF Space."""
29
  if not text.strip():
30
  raise gr.Error("Please enter a description.")
31
  for attempt in range(2):
 
93
 
94
  @spaces.GPU(duration=40)
95
  def infer(image, prompt):
96
+ """Generate an edited image from the input image and prompt."""
97
  negative_prompt = ""
98
  seed = random.randint(0, MAX_SEED)
99
  generator = torch.Generator(device=device).manual_seed(seed)
 
133
  @keyframes glow-hover {0%{box-shadow:0 0 20px rgba(0,255,128,0.7);}50%{box-shadow:0 0 20px rgba(0,255,128,0.9);}100%{box-shadow:0 0 20px rgba(0,255,128,0.7);}}
134
  @keyframes slide {0%{background-position:0% 50%;}50%{background-position:100% 50%;}100%{background-position:0% 50%;}}
135
  @keyframes pulse {0%,100%{opacity:0.7;}50%{opacity:1;}}
 
136
  body{
137
  background:#000000 !important;
138
  color:#FFFFFF !important;
 
179
  background:#000000 !important;
180
  border:none !important;
181
  border-radius:8px;
182
+ padding:1rem !important;
183
  box-shadow:0 0 10px rgba(255,255,255,0.3) !important;
184
  width:100% !important;
185
  max-width:100vw !important;
 
192
  text-align:center;
193
  color:#FFFFFF !important;
194
  text-shadow:0 0 8px rgba(255,255,255,0.3) !important;
195
+ margin:0 auto .5rem;
196
  display:block;
197
  max-width:100%;
198
  }
 
208
  .gradio-component{
209
  background:#000000 !important;
210
  border:none;
211
+ margin:0.75rem 0;
212
  width:100% !important;
213
  max-width:100vw !important;
214
  color:#FFFFFF !important;
 
226
  box-shadow:0 0 10px rgba(255,255,255,0.3) !important;
227
  position:relative;
228
  color:#FFFFFF !important;
 
229
  }
230
+ .image-container img{
231
  width:100% !important;
232
  height:auto;
233
  box-sizing:border-box !important;
 
290
  .image-container[aria-label="Result Image"].processing *{
291
  display:none !important;
292
  }
 
293
  .image-container[aria-label="Result Image"].processing img{
294
  display:none !important;
295
  }
296
+ input,textarea{
297
  background:#000000 !important;
298
  color:#FFFFFF !important;
299
  border:1px solid #FFFFFF !important;
 
303
  max-width:100vw !important;
304
  box-sizing:border-box !important;
305
  }
306
+ input:hover,textarea:hover{
307
  box-shadow:0 0 8px rgba(255,255,255,0.3) !important;
308
  transition:box-shadow 0.3s;
309
  }
 
332
  button[aria-label="Fullscreen"],button[aria-label="Share"],button[aria-label="Download"]{
333
  display:none !important;
334
  }
335
+ .progress-text,.gr-progress,.gr-prose,.gr-log{
336
+ display:none !important;
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
  footer,.gr-button-secondary{
339
  display:none !important;
 
350
  .gr-button-primary{
351
  padding:0.6rem 1rem;
352
  font-size:1rem;
353
+ box-shadow:0 0 10px rgba(0,255,128,0.7) !important;
354
+ animation:slide 4s ease-in-out infinite,glow 3s ease-in-out infinite;
355
  }
356
  .image-container{
357
  min-height:300px;
358
+ box-shadow:0 0 8px rgba(255,255,255,0.3) !important;
359
  }
360
  .image-container[aria-label="Result Image"].processing::before{
361
  font-size:1.2rem !important;
 
369
  throw new Error('500');
370
  }
371
  document.addEventListener('DOMContentLoaded', () => {
372
+ const generateBtn = document.querySelector('.gr-button-primary');
373
+ const resultContainer = document.querySelector('.image-container[aria-label="Result Image"]');
374
+ if (generateBtn && resultContainer) {
375
+ generateBtn.addEventListener('click', () => {
376
+ resultContainer.classList.add('processing');
377
+ resultContainer.querySelectorAll('*').forEach(child => {
378
+ if (child.tagName !== 'IMG') child.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  });
380
  });
381
+ const imgObserver = new MutationObserver(muts => {
382
+ muts.forEach(m => {
383
+ m.addedNodes.forEach(node => {
384
+ if (node.nodeType === 1 && (node.tagName === 'IMG' || node.querySelector('img'))) {
385
+ resultContainer.classList.remove('processing');
386
+ imgObserver.disconnect();
387
+ }
388
+ });
 
 
 
 
 
 
389
  });
390
  });
391
+ imgObserver.observe(resultContainer, { childList: true, subtree: true });
 
 
 
 
 
 
 
 
 
 
 
 
392
  }
393
  setInterval(() => {
394
+ document.querySelectorAll('.progress-text,.gr-progress,[class*="progress"]').forEach(el => el.remove());
 
 
395
  }, 500);
396
  });
397
  </script>
 
408
  show_download_button=False,
409
  show_share_button=False,
410
  interactive=True,
411
+ elem_classes=["gradio-component", "image-container"],
412
  )
413
  prompt = gr.Textbox(
414
  label="Prompt",
415
  lines=3,
416
+ elem_classes=["gradio-component"],
417
  )
418
  run_button = gr.Button(
419
  "Edit!",
420
  variant="primary",
421
+ elem_classes=["gradio-component", "gr-button-primary"],
422
  )
423
  result_image = gr.Image(
424
  label="Result Image",
 
426
  interactive=False,
427
  show_download_button=True,
428
  show_share_button=False,
429
+ elem_classes=["gradio-component", "image-container"],
430
  )
431
  run_button.click(fn=infer, inputs=[input_image, prompt], outputs=[result_image])
432
  prompt.submit(fn=infer, inputs=[input_image, prompt], outputs=[result_image])
 
434
 
435
  app = FastAPI()
436
  demo = create_demo()
437
+ app.mount("/y7u8i9o0p1l2k3j4h5g6f7d8s9a0q1w2e3r4t5y6u7i8o9p0l1k2j3h4g5f6d7s8", demo.app)
 
 
 
438
 
439
  @app.get("/{path:path}")
440
  async def catch_all(path: str):