druvx13 commited on
Commit
64165f0
·
verified ·
1 Parent(s): 02e391d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -17,7 +17,8 @@ pipe = StableDiffusionPipeline.from_pretrained(
17
  torch_dtype=torch.float32,
18
  cache_dir=CACHE_DIR,
19
  low_cpu_mem_usage=True,
20
- safety_checker=None
 
21
  )
22
 
23
  DISCLAIMER = """
@@ -40,18 +41,27 @@ def generate_image(prompt, width, height, num_inference_steps=20, guidance_scale
40
  height = height - (height % 8)
41
 
42
  with torch.inference_mode():
 
43
  result = pipe(
44
- prompt=prompt,
45
- width=width,
46
- height=height,
47
- num_inference_steps=num_inference_steps,
48
- guidance_scale=guidance_scale
49
- ).images[0]
 
50
 
51
- if result is None:
52
- return None, "Error: Failed to generate image"
 
 
 
 
 
 
 
53
 
54
- return result.convert("RGB"), f"Success ({width}x{height})"
55
 
56
  except Exception as e:
57
  return None, f"Generation Error: {str(e)}"
 
17
  torch_dtype=torch.float32,
18
  cache_dir=CACHE_DIR,
19
  low_cpu_mem_usage=True,
20
+ safety_checker=None,
21
+ use_safetensors=True # More reliable on CPU
22
  )
23
 
24
  DISCLAIMER = """
 
41
  height = height - (height % 8)
42
 
43
  with torch.inference_mode():
44
+ # Generate with explicit parameter casting
45
  result = pipe(
46
+ prompt=str(prompt),
47
+ width=int(width),
48
+ height=int(height),
49
+ num_inference_steps=int(num_inference_steps),
50
+ guidance_scale=float(guidance_scale),
51
+ generator=None # Avoid seed-related issues
52
+ )
53
 
54
+ # Strict output validation
55
+ if not hasattr(result, "images") or not isinstance(result.images, list):
56
+ return None, f"Invalid pipeline output format: {type(result)}"
57
+
58
+ if len(result.images) == 0:
59
+ return None, "Pipeline returned empty image list"
60
+
61
+ if result.images[0] is None:
62
+ return None, "Pipeline returned None image"
63
 
64
+ return result.images[0].convert("RGB"), f"Success ({width}x{height})"
65
 
66
  except Exception as e:
67
  return None, f"Generation Error: {str(e)}"