ginipick commited on
Commit
975601a
Β·
verified Β·
1 Parent(s): 5c4cc9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -7
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import random
2
  import os
3
  import uuid
@@ -8,6 +9,14 @@ import spaces
8
  import torch
9
  from diffusers import DiffusionPipeline
10
  from PIL import Image
 
 
 
 
 
 
 
 
11
 
12
  # Temporary fix to patch the gradio_client.utils module
13
  import gradio_client.utils
@@ -25,13 +34,37 @@ SAVE_DIR = "saved_images" # Gradio will handle the persistence
25
  if not os.path.exists(SAVE_DIR):
26
  os.makedirs(SAVE_DIR, exist_ok=True)
27
 
28
- device = "cuda" if torch.cuda.is_available() else "cpu"
29
- repo_id = "black-forest-labs/FLUX.1-dev"
30
- adapter_id = "openfree/flux-chatgpt-ghibli-lora"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
33
- pipeline.load_lora_weights(adapter_id)
34
- pipeline = pipeline.to(device)
35
 
36
  MAX_SEED = np.iinfo(np.int32).max
37
  MAX_IMAGE_SIZE = 1024
@@ -233,5 +266,12 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, analytics_enabled=Fa
233
  outputs=[result, seed, generated_gallery],
234
  )
235
 
 
236
  demo.queue()
237
- demo.launch()
 
 
 
 
 
 
 
1
+
2
  import random
3
  import os
4
  import uuid
 
9
  import torch
10
  from diffusers import DiffusionPipeline
11
  from PIL import Image
12
+ import huggingface_hub
13
+ import requests
14
+ from tqdm.auto import tqdm
15
+ import time
16
+
17
+ # νƒ€μž„μ•„μ›ƒ κ°’ 증가 μ„€μ •
18
+ huggingface_hub.constants.DEFAULT_ETAG_TIMEOUT = 30
19
+ huggingface_hub.constants.DEFAULT_DOWNLOAD_TIMEOUT = 120
20
 
21
  # Temporary fix to patch the gradio_client.utils module
22
  import gradio_client.utils
 
34
  if not os.path.exists(SAVE_DIR):
35
  os.makedirs(SAVE_DIR, exist_ok=True)
36
 
37
+ # λͺ¨λΈ λ‘œλ”© ν•¨μˆ˜ - μž¬μ‹œλ„ 둜직 μΆ”κ°€
38
+ def load_model_with_retry(max_retries=5):
39
+ device = "cuda" if torch.cuda.is_available() else "cpu"
40
+ repo_id = "black-forest-labs/FLUX.1-dev"
41
+ adapter_id = "openfree/flux-chatgpt-ghibli-lora"
42
+
43
+ for attempt in range(max_retries):
44
+ try:
45
+ print(f"Loading model attempt {attempt+1}/{max_retries}...")
46
+ pipeline = DiffusionPipeline.from_pretrained(
47
+ repo_id,
48
+ torch_dtype=torch.bfloat16,
49
+ use_safetensors=True,
50
+ resume_download=True
51
+ )
52
+ print("Model loaded successfully, loading LoRA weights...")
53
+ pipeline.load_lora_weights(adapter_id)
54
+ pipeline = pipeline.to(device)
55
+ print("Pipeline ready!")
56
+ return pipeline, device
57
+ except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError) as e:
58
+ if attempt < max_retries - 1:
59
+ wait_time = 10 * (attempt + 1) # μ μ§„μ μœΌλ‘œ λŒ€κΈ° μ‹œκ°„ 증가
60
+ print(f"Download timed out or connection error: {e}. Retrying in {wait_time} seconds...")
61
+ time.sleep(wait_time)
62
+ else:
63
+ raise Exception(f"Failed to download model after {max_retries} attempts: {e}")
64
 
65
+ # λͺ¨λΈ λ‘œλ“œ μ‹œμž‘
66
+ print("Starting model loading process...")
67
+ pipeline, device = load_model_with_retry()
68
 
69
  MAX_SEED = np.iinfo(np.int32).max
70
  MAX_IMAGE_SIZE = 1024
 
266
  outputs=[result, seed, generated_gallery],
267
  )
268
 
269
+ # Launch with explicit host and port
270
  demo.queue()
271
+ try:
272
+ demo.launch(share=False)
273
+ except Exception as e:
274
+ print(f"Error during launch: {e}")
275
+ # μ—λŸ¬ λ°œμƒ μ‹œ, κ°„μ†Œν™”λœ λ²„μ „μœΌλ‘œ μž¬μ‹œλ„
276
+ print("Retrying with simplified launch...")
277
+ demo.launch(share=False, ssl_verify=False)