dedlepexa commited on
Commit
2cb1925
·
verified ·
1 Parent(s): f74d7d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -6,7 +6,7 @@ import threading
6
  import time
7
  from collections import OrderedDict
8
  import os
9
- from PIL import Image # 🔥 NEW
10
 
11
  app = FastAPI()
12
 
@@ -16,7 +16,7 @@ app = FastAPI()
16
  torch.set_num_threads(2)
17
 
18
  # =========================
19
- # 🔥 MODEL (ТВОЙ РАБОЧИЙ)
20
  # =========================
21
  model_name = "Lykon/dreamshaper-7"
22
 
@@ -28,10 +28,6 @@ pipe = StableDiffusionPipeline.from_pretrained(
28
 
29
  pipe = pipe.to("cpu")
30
 
31
- # 🔥 LCM LoRA (оставляем как у тебя)
32
- pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")
33
- pipe.fuse_lora()
34
-
35
  pipe.enable_attention_slicing()
36
 
37
  # =========================
@@ -42,11 +38,13 @@ queue = []
42
  progress_db = {}
43
 
44
  MAX_HISTORY = 40
 
 
45
  IMG_DIR = "images"
46
  os.makedirs(IMG_DIR, exist_ok=True)
47
 
48
  # =========================
49
- # ✂️ SPLIT FUNCTION (12 частей)
50
  # =========================
51
  def split_image_into_12(img_path: str):
52
 
@@ -87,29 +85,28 @@ def generate_ai_stream(message: str, mode="fast"):
87
 
88
  try:
89
  start = time.time()
90
- progress_db[message] = 0
91
 
92
- # ⚡ FAST / QUALITY
93
  if mode == "fast":
94
- steps = 4
95
  cfg = 1.5
96
- h, w = 256, 256
97
  else:
98
- steps = 12
99
- cfg = 6.5
100
- h, w = 512, 512
 
101
 
102
- # 🔥 fake progress
103
  for i in range(steps):
104
  progress_db[message] = int((i / steps) * 100)
105
- time.sleep(0.08)
106
 
107
  image = pipe(
108
  message,
109
  num_inference_steps=steps,
110
  guidance_scale=cfg,
111
- height=h,
112
- width=w
113
  ).images[0]
114
 
115
  filename = f"{IMG_DIR}/img_{int(time.time()*1000)}.png"
@@ -161,10 +158,9 @@ threading.Thread(target=worker, daemon=True).start()
161
 
162
  @app.get("/")
163
  async def root():
164
- return PlainTextResponse("⚡ Dreamshaper + LCM + FAST/QUALITY + SPLIT 12 READY")
165
 
166
 
167
- # 🚀 FAST MODE
168
  @app.get("/fast")
169
  async def fast(message: str):
170
 
@@ -178,7 +174,6 @@ async def fast(message: str):
178
  return PlainTextResponse("accepted")
179
 
180
 
181
- # 🎨 QUALITY MODE
182
  @app.get("/quality")
183
  async def quality(message: str):
184
 
@@ -192,7 +187,6 @@ async def quality(message: str):
192
  return PlainTextResponse("accepted")
193
 
194
 
195
- # 📡 GET + PROGRESS
196
  @app.get("/get")
197
  async def get(message: str):
198
 
@@ -208,7 +202,6 @@ async def get(message: str):
208
  return PlainTextResponse(data["reply"])
209
 
210
 
211
- # 🖼 FILE SERVE
212
  @app.get("/image")
213
  async def get_image(path: str):
214
 
 
6
  import time
7
  from collections import OrderedDict
8
  import os
9
+ from PIL import Image # 🔥 ДОБАВЛЕНО
10
 
11
  app = FastAPI()
12
 
 
16
  torch.set_num_threads(2)
17
 
18
  # =========================
19
+ # 🔥 MODEL
20
  # =========================
21
  model_name = "Lykon/dreamshaper-7"
22
 
 
28
 
29
  pipe = pipe.to("cpu")
30
 
 
 
 
 
31
  pipe.enable_attention_slicing()
32
 
33
  # =========================
 
38
  progress_db = {}
39
 
40
  MAX_HISTORY = 40
41
+ NUM_WORKERS = 1
42
+
43
  IMG_DIR = "images"
44
  os.makedirs(IMG_DIR, exist_ok=True)
45
 
46
  # =========================
47
+ # ✂️ 12 SPLIT FUNCTION (NEW)
48
  # =========================
49
  def split_image_into_12(img_path: str):
50
 
 
85
 
86
  try:
87
  start = time.time()
 
88
 
89
+ # ⚡ режимы
90
  if mode == "fast":
91
+ steps = 2
92
  cfg = 1.5
 
93
  else:
94
+ steps = 6
95
+ cfg = 3.0
96
+
97
+ progress_db[message] = 0
98
 
99
+ # 🔥 fake-progress
100
  for i in range(steps):
101
  progress_db[message] = int((i / steps) * 100)
102
+ time.sleep(0.12)
103
 
104
  image = pipe(
105
  message,
106
  num_inference_steps=steps,
107
  guidance_scale=cfg,
108
+ height=256,
109
+ width=256
110
  ).images[0]
111
 
112
  filename = f"{IMG_DIR}/img_{int(time.time()*1000)}.png"
 
158
 
159
  @app.get("/")
160
  async def root():
161
+ return PlainTextResponse("⚡ CPU LCM Image Generator Running")
162
 
163
 
 
164
  @app.get("/fast")
165
  async def fast(message: str):
166
 
 
174
  return PlainTextResponse("accepted")
175
 
176
 
 
177
  @app.get("/quality")
178
  async def quality(message: str):
179
 
 
187
  return PlainTextResponse("accepted")
188
 
189
 
 
190
  @app.get("/get")
191
  async def get(message: str):
192
 
 
202
  return PlainTextResponse(data["reply"])
203
 
204
 
 
205
  @app.get("/image")
206
  async def get_image(path: str):
207