prithivMLmods commited on
Commit
e5212fe
·
verified ·
1 Parent(s): b4b6b69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -33
app.py CHANGED
@@ -151,22 +151,6 @@ if torch.cuda.is_available():
151
  pipe2.unet = torch.compile(pipe2.unet, mode="reduce-overhead", fullgraph=True)
152
  print("Model RealVisXL_V4.0 Compiled!")
153
 
154
- # Turbo v3 model
155
- pipe3 = StableDiffusionXLPipeline.from_pretrained(
156
- "SG161222/RealVisXL_V3.0_Turbo",
157
- torch_dtype=dtype,
158
- use_safetensors=True,
159
- add_watermarker=False,
160
- ).to(device)
161
- pipe3.text_encoder = pipe3.text_encoder.half()
162
- if ENABLE_CPU_OFFLOAD:
163
- pipe3.enable_model_cpu_offload()
164
- else:
165
- pipe3.to(device)
166
- print("Loaded RealVisXL_V3.0_Turbo on Device!")
167
- if USE_TORCH_COMPILE:
168
- pipe3.unet = torch.compile(pipe3.unet, mode="reduce-overhead", fullgraph=True)
169
- print("Model RealVisXL_V3.0_Turbo Compiled!")
170
  else:
171
  pipe = StableDiffusionXLPipeline.from_pretrained(
172
  "SG161222/RealVisXL_V5.0_Lightning",
@@ -180,20 +164,13 @@ else:
180
  use_safetensors=True,
181
  add_watermarker=False,
182
  ).to(device)
183
- pipe3 = StableDiffusionXLPipeline.from_pretrained(
184
- "SG161222/RealVisXL_V3.0_Turbo",
185
- torch_dtype=dtype,
186
- use_safetensors=True,
187
- add_watermarker=False,
188
- ).to(device)
189
  print("Running on CPU; models loaded in float32.")
190
 
191
  DEFAULT_MODEL = "Lightning 5"
192
- MODEL_CHOICES = [DEFAULT_MODEL, "Lightning 4", "Turbo v3"]
193
  models = {
194
  "Lightning 5": pipe,
195
- "Lightning 4": pipe2,
196
- "Turbo v3": pipe3
197
  }
198
 
199
  def save_image(img: Image.Image) -> str:
@@ -248,8 +225,7 @@ def generate(
248
 
249
  # IMAGE GENERATION BRANCH (Stable Diffusion models)
250
  if (lower_text.startswith("@lightningv5") or
251
- lower_text.startswith("@lightningv4") or
252
- lower_text.startswith("@turbov3")):
253
 
254
  # Determine model choice based on flag.
255
  model_choice = None
@@ -257,13 +233,10 @@ def generate(
257
  model_choice = "Lightning 5"
258
  elif "@lightningv4" in lower_text:
259
  model_choice = "Lightning 4"
260
- elif "@turbov3" in lower_text:
261
- model_choice = "Turbo v3"
262
 
263
  # Remove the model flag from the prompt.
264
  prompt_clean = re.sub(r"@lightningv5", "", text, flags=re.IGNORECASE)
265
  prompt_clean = re.sub(r"@lightningv4", "", prompt_clean, flags=re.IGNORECASE)
266
- prompt_clean = re.sub(r"@turbov3", "", prompt_clean, flags=re.IGNORECASE)
267
  prompt_clean = prompt_clean.strip().strip('"')
268
 
269
  # Default parameters for single image generation.
@@ -481,7 +454,6 @@ demo = gr.ChatInterface(
481
  gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2),
482
  ],
483
  examples=[
484
-
485
  [{"text": "@gemma3-4b Explain the Image", "files": ["examples/3.jpg"]}],
486
  [{"text": "@video-infer Explain the content of the Advertisement", "files": ["examples/videoplayback.mp4"]}],
487
  [{"text": "@video-infer Explain the content of the video in detail", "files": ["examples/breakfast.mp4"]}],
@@ -495,14 +467,13 @@ demo = gr.ChatInterface(
495
  ["Python Program for Array Rotation"],
496
  ["@tts1 Who is Nikola Tesla, and why did he die?"],
497
  ['@lightningv4 Cat holding a sign that says hello world'],
498
- ['@turbov3 Anime illustration of a wiener schnitzel'],
499
  ["@tts2 What causes rainbows to form?"],
500
  ],
501
  cache_examples=False,
502
  type="messages",
503
  description="# **Gemma 3 `@gemma3-4b, @video-infer for video understanding`**",
504
  fill_height=True,
505
- textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image", "video"], file_count="multiple", placeholder="@gemma3-4b for multimodal, @video-infer for video, @lightningv5, @lightningv4, @turbov3 for image gen !"),
506
  stop_btn="Stop Generation",
507
  multimodal=True,
508
  )
 
151
  pipe2.unet = torch.compile(pipe2.unet, mode="reduce-overhead", fullgraph=True)
152
  print("Model RealVisXL_V4.0 Compiled!")
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  else:
155
  pipe = StableDiffusionXLPipeline.from_pretrained(
156
  "SG161222/RealVisXL_V5.0_Lightning",
 
164
  use_safetensors=True,
165
  add_watermarker=False,
166
  ).to(device)
 
 
 
 
 
 
167
  print("Running on CPU; models loaded in float32.")
168
 
169
  DEFAULT_MODEL = "Lightning 5"
170
+ MODEL_CHOICES = [DEFAULT_MODEL, "Lightning 4"]
171
  models = {
172
  "Lightning 5": pipe,
173
+ "Lightning 4": pipe2
 
174
  }
175
 
176
  def save_image(img: Image.Image) -> str:
 
225
 
226
  # IMAGE GENERATION BRANCH (Stable Diffusion models)
227
  if (lower_text.startswith("@lightningv5") or
228
+ lower_text.startswith("@lightningv4")):
 
229
 
230
  # Determine model choice based on flag.
231
  model_choice = None
 
233
  model_choice = "Lightning 5"
234
  elif "@lightningv4" in lower_text:
235
  model_choice = "Lightning 4"
 
 
236
 
237
  # Remove the model flag from the prompt.
238
  prompt_clean = re.sub(r"@lightningv5", "", text, flags=re.IGNORECASE)
239
  prompt_clean = re.sub(r"@lightningv4", "", prompt_clean, flags=re.IGNORECASE)
 
240
  prompt_clean = prompt_clean.strip().strip('"')
241
 
242
  # Default parameters for single image generation.
 
454
  gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2),
455
  ],
456
  examples=[
 
457
  [{"text": "@gemma3-4b Explain the Image", "files": ["examples/3.jpg"]}],
458
  [{"text": "@video-infer Explain the content of the Advertisement", "files": ["examples/videoplayback.mp4"]}],
459
  [{"text": "@video-infer Explain the content of the video in detail", "files": ["examples/breakfast.mp4"]}],
 
467
  ["Python Program for Array Rotation"],
468
  ["@tts1 Who is Nikola Tesla, and why did he die?"],
469
  ['@lightningv4 Cat holding a sign that says hello world'],
 
470
  ["@tts2 What causes rainbows to form?"],
471
  ],
472
  cache_examples=False,
473
  type="messages",
474
  description="# **Gemma 3 `@gemma3-4b, @video-infer for video understanding`**",
475
  fill_height=True,
476
+ textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image", "video"], file_count="multiple", placeholder="@gemma3-4b for multimodal, @video-infer for video, @lightningv5, @lightningv4 for image gen !"),
477
  stop_btn="Stop Generation",
478
  multimodal=True,
479
  )