soiz commited on
Commit
8c4ccaa
β€’
1 Parent(s): 1255cd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -27,7 +27,7 @@ def load_model(model_name):
27
  print(f"Error loading model {model_name}: {error}")
28
  models_load[model_name] = gr.Interface(lambda txt: None, ['text'], ['image'])
29
 
30
- def gen_fn(model_str, prompt, negative_prompt=None, noise=None, cfg_scale=0):
31
  if model_str not in models_load:
32
  load_model(model_str) # γƒ’γƒ‡γƒ«γŒγƒ­γƒΌγƒ‰γ•γ‚Œγ¦γ„γͺγ„ε ΄εˆγ―γƒ­γƒΌγƒ‰γ™γ‚‹
33
 
@@ -38,8 +38,11 @@ def gen_fn(model_str, prompt, negative_prompt=None, noise=None, cfg_scale=0):
38
  try:
39
  if negative_prompt:
40
  full_prompt += f' -{negative_prompt}'
41
- # Assuming models_load[model_str] accepts cfg_scale as a parameter
42
- result = models_load[model_str](full_prompt, cfg_scale=cfg_scale)
 
 
 
43
  # Check if result is an image or a file path
44
  if isinstance(result, str): # Assuming result might be a file path
45
  if os.path.exists(result):
@@ -65,10 +68,11 @@ def home():
65
  model = request.args.get('model', '')
66
  negative_prompt = request.args.get('Nprompt', None)
67
  noise = request.args.get('noise', None)
68
- cfg_scale = request.args.get('cfg_scale', 0)
69
 
70
  try:
71
- cfg_scale = float(cfg_scale)
 
72
  except ValueError:
73
  return 'Invalid "cfg_scale" parameter. It should be a number.', 400
74
 
 
27
  print(f"Error loading model {model_name}: {error}")
28
  models_load[model_name] = gr.Interface(lambda txt: None, ['text'], ['image'])
29
 
30
+ def gen_fn(model_str, prompt, negative_prompt=None, noise=None, cfg_scale=None):
31
  if model_str not in models_load:
32
  load_model(model_str) # γƒ’γƒ‡γƒ«γŒγƒ­γƒΌγƒ‰γ•γ‚Œγ¦γ„γͺγ„ε ΄εˆγ―γƒ­γƒΌγƒ‰γ™γ‚‹
33
 
 
38
  try:
39
  if negative_prompt:
40
  full_prompt += f' -{negative_prompt}'
41
+ # Adjust function call based on whether cfg_scale is provided
42
+ if cfg_scale is not None:
43
+ result = models_load[model_str](full_prompt, cfg_scale=cfg_scale)
44
+ else:
45
+ result = models_load[model_str](full_prompt)
46
  # Check if result is an image or a file path
47
  if isinstance(result, str): # Assuming result might be a file path
48
  if os.path.exists(result):
 
68
  model = request.args.get('model', '')
69
  negative_prompt = request.args.get('Nprompt', None)
70
  noise = request.args.get('noise', None)
71
+ cfg_scale = request.args.get('cfg_scale', None)
72
 
73
  try:
74
+ if cfg_scale is not None:
75
+ cfg_scale = float(cfg_scale)
76
  except ValueError:
77
  return 'Invalid "cfg_scale" parameter. It should be a number.', 400
78