Update app.py
Browse files
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=
|
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 |
-
#
|
42 |
-
|
|
|
|
|
|
|
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',
|
69 |
|
70 |
try:
|
71 |
-
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 |
|