CryptoCreeper commited on
Commit
8868bd0
·
verified ·
1 Parent(s): 6194646

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -46
app.py CHANGED
@@ -6,7 +6,7 @@ import re
6
  from diffusers import DiffusionPipeline, LCMScheduler
7
 
8
  # -------------------------------------------------
9
- # MODEL SETUP (CPU SAFE)
10
  # -------------------------------------------------
11
  model_id = "runwayml/stable-diffusion-v1-5"
12
  adapter_id = "latent-consistency/lcm-lora-sdv1-5"
@@ -25,56 +25,73 @@ pipe.enable_vae_slicing()
25
  pipe.set_progress_bar_config(disable=True)
26
 
27
  # -------------------------------------------------
28
- # EXCELLENT UNDERSTANDING ENGINE (FAST, NO ML)
29
  # -------------------------------------------------
30
  def refine_prompt(user_prompt: str):
31
  p = user_prompt.lower()
32
 
33
- # Detect style intent
34
- is_cute = any(k in p for k in ["cute", "adorable", "kawaii"])
35
- is_realistic = any(k in p for k in ["realistic", "photo", "photograph"])
36
- is_cartoon = any(k in p for k in ["cartoon", "anime", "illustration"])
37
 
38
- # Detect animal
39
- animal_match = re.search(
40
- r"(snake|cat|dog|dragon|bird|fox|rabbit|lion|tiger)", p
41
  )
 
42
 
43
- subject = animal_match.group(1) if animal_match else user_prompt
44
-
45
- # Base object enforcement
46
- prompt = f"a single {subject}, centered, isolated"
 
47
 
48
- # Style refinement
49
  if is_cute:
50
  prompt += (
51
- ", cute, friendly, rounded shapes, big expressive eyes, "
52
- "soft lighting, smooth colors"
 
53
  )
54
- elif is_cartoon:
55
- prompt += ", cartoon style, clean lines, vibrant colors"
56
  elif is_realistic:
57
- prompt += ", ultra realistic, sharp focus, professional photography"
 
 
 
58
  else:
59
- prompt += ", high quality, detailed"
60
 
61
- prompt += ", simple background"
62
 
63
  negative = (
64
- "multiple subjects, duplicate, horror, scary, grotesque, "
65
- "deformed, blurry, low quality, background clutter"
 
66
  )
67
 
68
  return prompt, negative
69
 
70
  # -------------------------------------------------
71
- # GENERATION
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  # -------------------------------------------------
73
  def generate(prompt, resolution, steps):
74
  start = time.time()
 
75
 
76
  refined_prompt, neg_prompt = refine_prompt(prompt)
77
 
 
 
78
  seed = random.randint(0, 10**9)
79
  gen = torch.Generator("cpu").manual_seed(seed)
80
 
@@ -88,27 +105,14 @@ def generate(prompt, resolution, steps):
88
  generator=gen
89
  ).images[0]
90
 
91
- duration = round(time.time() - start, 2)
92
- status = f"✅ Generated in {duration}s | Seed: {seed}"
93
-
94
- return [img], status
95
-
96
- # -------------------------------------------------
97
- # FAST & REALISTIC ETA ( < 10 ms )
98
- # -------------------------------------------------
99
- def estimate_time(steps, resolution):
100
- base_overhead = 1.2
101
- res_factor = (int(resolution) / 512) ** 2
102
- step_cost = 0.35
103
-
104
- est = base_overhead + (steps * step_cost * res_factor)
105
- return f"⚡ Estimated time: ~{round(est, 1)}s"
106
 
107
  # -------------------------------------------------
108
  # UI
109
  # -------------------------------------------------
110
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
111
- gr.Markdown("# 👾 CREEPER AI — IMAGE (SMART CORE)")
112
 
113
  with gr.Row():
114
  with gr.Column():
@@ -125,14 +129,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
125
  )
126
 
127
  steps = gr.Slider(
128
- minimum=2,
129
- maximum=10,
130
- value=4,
131
- step=1,
132
- label="Steps"
133
  )
134
 
135
- eta = gr.Markdown(" Estimated time: ~2.5s")
136
  btn = gr.Button("Generate")
137
 
138
  with gr.Column():
 
6
  from diffusers import DiffusionPipeline, LCMScheduler
7
 
8
  # -------------------------------------------------
9
+ # MODEL SETUP (CPU REALITY MODE)
10
  # -------------------------------------------------
11
  model_id = "runwayml/stable-diffusion-v1-5"
12
  adapter_id = "latent-consistency/lcm-lora-sdv1-5"
 
25
  pipe.set_progress_bar_config(disable=True)
26
 
27
  # -------------------------------------------------
28
+ # STRONG PROMPT UNDERSTANDING (ANIMAL-SAFE)
29
  # -------------------------------------------------
30
  def refine_prompt(user_prompt: str):
31
  p = user_prompt.lower()
32
 
33
+ is_cute = any(w in p for w in ["cute", "adorable", "kawaii"])
34
+ is_realistic = any(w in p for w in ["realistic", "photo", "photograph"])
 
 
35
 
36
+ animal = re.search(
37
+ r"(snake|cat|dog|fox|rabbit|dragon|bird|frog|hamster)", p
 
38
  )
39
+ subject = animal.group(1) if animal else user_prompt
40
 
41
+ # CORE STRUCTURE (this is crucial)
42
+ prompt = (
43
+ f"a single small {subject}, full body visible, "
44
+ f"centered composition, facing camera"
45
+ )
46
 
 
47
  if is_cute:
48
  prompt += (
49
+ ", cute, friendly, rounded body, "
50
+ "big expressive eyes, soft lighting, "
51
+ "smooth cartoon style, pastel colors"
52
  )
 
 
53
  elif is_realistic:
54
+ prompt += (
55
+ ", ultra realistic, natural anatomy, "
56
+ "professional wildlife photography"
57
+ )
58
  else:
59
+ prompt += ", clean illustration style, detailed"
60
 
61
+ prompt += ", simple plain background"
62
 
63
  negative = (
64
+ "multiple animals, duplicate, scary, horror, grotesque, "
65
+ "realistic snake scales, fangs, aggression, "
66
+ "blurry, low quality, cropped, out of frame"
67
  )
68
 
69
  return prompt, negative
70
 
71
  # -------------------------------------------------
72
+ # REALISTIC ETA (CPU HONEST)
73
+ # -------------------------------------------------
74
+ def estimate_time(steps, resolution):
75
+ # Measured HF Free CPU averages
76
+ base = 20 # model overhead
77
+ step_cost_512 = 22 # seconds per step @512
78
+
79
+ scale = (int(resolution) / 512) ** 2
80
+ est = base + (steps * step_cost_512 * scale)
81
+
82
+ return f"⏱️ Estimated time: ~{int(est)} seconds"
83
+
84
+ # -------------------------------------------------
85
+ # GENERATION WITH LIVE STATUS
86
  # -------------------------------------------------
87
  def generate(prompt, resolution, steps):
88
  start = time.time()
89
+ yield None, "🧠 Understanding your prompt..."
90
 
91
  refined_prompt, neg_prompt = refine_prompt(prompt)
92
 
93
+ yield None, "🎨 Generating image (CPU, this takes time)..."
94
+
95
  seed = random.randint(0, 10**9)
96
  gen = torch.Generator("cpu").manual_seed(seed)
97
 
 
105
  generator=gen
106
  ).images[0]
107
 
108
+ duration = int(time.time() - start)
109
+ yield [img], f"✅ Finished in {duration}s | Seed: {seed}"
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  # -------------------------------------------------
112
  # UI
113
  # -------------------------------------------------
114
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
115
+ gr.Markdown("# 👾 CREEPER AI — CPU HONEST MODE")
116
 
117
  with gr.Row():
118
  with gr.Column():
 
129
  )
130
 
131
  steps = gr.Slider(
132
+ 2, 10, value=4, step=1, label="Steps"
 
 
 
 
133
  )
134
 
135
+ eta = gr.Markdown("⏱️ Estimated time: ~90 seconds")
136
  btn = gr.Button("Generate")
137
 
138
  with gr.Column():