multimodalart HF staff commited on
Commit
3898fa4
1 Parent(s): 8485d74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -2,12 +2,14 @@ import gradio as gr
2
  from PIL import Image
3
  import requests
4
  import subprocess
5
- import spaces
 
 
 
6
  from transformers import Blip2Processor, Blip2ForConditionalGeneration
7
  from huggingface_hub import snapshot_download, HfApi
8
  import torch
9
  import uuid
10
- import os
11
  import shutil
12
  import json
13
  import random
@@ -20,8 +22,6 @@ import zipfile
20
 
21
  MAX_IMAGES = 150
22
 
23
- is_spaces = True if os.environ.get('SPACE_ID') else False
24
-
25
  training_script_url = "https://raw.githubusercontent.com/huggingface/diffusers/ba28006f8b2a0f7ec3b6784695790422b4f80a97/examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py"
26
  subprocess.run(['wget', '-N', training_script_url])
27
  orchestrator_script_url = "https://huggingface.co/datasets/multimodalart/lora-ease-helper/raw/main/script.py"
@@ -501,7 +501,7 @@ def start_training_og(
501
 
502
  return f"Your model has finished training and has been saved to the `{slugged_lora_name}` folder"
503
 
504
- @spaces.GPU(enable_queue=True)
505
  def run_captioning(*inputs):
506
  model.to("cuda")
507
  images = inputs[0]
@@ -520,6 +520,10 @@ def run_captioning(*inputs):
520
  final_captions[index] = final_caption
521
  yield final_captions
522
 
 
 
 
 
523
  def check_token(token):
524
  try:
525
  api = HfApi(token=token)
 
2
  from PIL import Image
3
  import requests
4
  import subprocess
5
+ import os
6
+ is_spaces = True if os.environ.get('SPACE_ID') else False
7
+ if(is_spaces):
8
+ import spaces
9
  from transformers import Blip2Processor, Blip2ForConditionalGeneration
10
  from huggingface_hub import snapshot_download, HfApi
11
  import torch
12
  import uuid
 
13
  import shutil
14
  import json
15
  import random
 
22
 
23
  MAX_IMAGES = 150
24
 
 
 
25
  training_script_url = "https://raw.githubusercontent.com/huggingface/diffusers/ba28006f8b2a0f7ec3b6784695790422b4f80a97/examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py"
26
  subprocess.run(['wget', '-N', training_script_url])
27
  orchestrator_script_url = "https://huggingface.co/datasets/multimodalart/lora-ease-helper/raw/main/script.py"
 
501
 
502
  return f"Your model has finished training and has been saved to the `{slugged_lora_name}` folder"
503
 
504
+ @spaces.GPU()
505
  def run_captioning(*inputs):
506
  model.to("cuda")
507
  images = inputs[0]
 
520
  final_captions[index] = final_caption
521
  yield final_captions
522
 
523
+ if is_spaces:
524
+ run_captioning = spaces.GPU()(run_captioning)
525
+
526
+
527
  def check_token(token):
528
  try:
529
  api = HfApi(token=token)