ParahumanSkitter commited on
Commit
d056990
·
verified ·
1 Parent(s): 2ed16c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -2,8 +2,6 @@ import gradio as gr
2
  from random import randint
3
  from all_models import models
4
  from datetime import datetime
5
- from diffusers import StableDiffusionImg2ImgPipeline
6
- import torch
7
 
8
  def get_current_time():
9
  now = datetime.now()
@@ -18,10 +16,7 @@ def load_fn(models):
18
  for model in models:
19
  if model not in models_load.keys():
20
  try:
21
- if 'img2img' in model.lower(): # Assuming models with 'img2img' in their name are image-to-image models
22
- m = StableDiffusionImg2ImgPipeline.from_pretrained(f'models/{model}')
23
- else:
24
- m = gr.load(f'models/{model}')
25
  except Exception as error:
26
  m = gr.Interface(lambda txt: None, ['text'], ['image'])
27
  models_load.update({model: m})
@@ -72,7 +67,10 @@ def img_to_img_fn(model_str, image, prompt, negative_prompt, max_retries=10):
72
  while retries < max_retries:
73
  try:
74
  noise = str(randint(0, 9999999))
75
- result = models_load[model_str](prompt=f'{prompt} {noise}', negative_prompt=negative_prompt, image=image).images[0]
 
 
 
76
  return result
77
  except Exception as e:
78
  # Check for specific error messages or status codes
 
2
  from random import randint
3
  from all_models import models
4
  from datetime import datetime
 
 
5
 
6
  def get_current_time():
7
  now = datetime.now()
 
16
  for model in models:
17
  if model not in models_load.keys():
18
  try:
19
+ m = gr.load(f'models/{model}')
 
 
 
20
  except Exception as error:
21
  m = gr.Interface(lambda txt: None, ['text'], ['image'])
22
  models_load.update({model: m})
 
67
  while retries < max_retries:
68
  try:
69
  noise = str(randint(0, 9999999))
70
+ if hasattr(models_load[model_str], 'negative_prompt'):
71
+ result = models_load[model_str](image=image, prompt=f'{prompt} {noise}', negative_prompt=negative_prompt)
72
+ else:
73
+ result = models_load[model_str](image=image, prompt=f'{prompt} {noise}')
74
  return result
75
  except Exception as e:
76
  # Check for specific error messages or status codes