soiz commited on
Commit
79d4fbf
1 Parent(s): 58582ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -38,12 +38,15 @@ def update_imgbox(choices):
38
  choices_plus = extend_choices(choices)
39
  return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
40
 
41
- def gen_fn(model_str, prompt):
42
  if model_str == 'NA':
43
  return None
44
  noise = str('') # Optional: str(randint(0, 99999999999))
45
  try:
46
- result = models_load[model_str](f'{prompt} {noise}')
 
 
 
47
  # Check if result is an image or a file path
48
  if isinstance(result, str): # Assuming result might be a file path
49
  if os.path.exists(result):
@@ -64,13 +67,14 @@ def gen_fn(model_str, prompt):
64
  def home():
65
  prompt = request.args.get('prompt', '')
66
  model = request.args.get('model', default_models[0] if default_models else 'NA')
 
67
 
68
  if not model or model not in models_load:
69
  return f'Invalid model: {model}', 400
70
 
71
  if prompt:
72
  # Generate the image
73
- image = gen_fn(model, prompt)
74
  if isinstance(image, Image.Image): # Ensure the result is a PIL image
75
  # Save image to BytesIO object
76
  img_io = BytesIO()
@@ -82,4 +86,4 @@ def home():
82
 
83
  if __name__ == '__main__':
84
  # Launch Flask app
85
- app.run(host='0.0.0.0', port=7860) # Run Flask app
 
38
  choices_plus = extend_choices(choices)
39
  return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
40
 
41
+ def gen_fn(model_str, prompt, negative_prompt=None):
42
  if model_str == 'NA':
43
  return None
44
  noise = str('') # Optional: str(randint(0, 99999999999))
45
  try:
46
+ full_prompt = f'{prompt} {noise}'
47
+ if negative_prompt:
48
+ full_prompt += f' -{negative_prompt}'
49
+ result = models_load[model_str](full_prompt)
50
  # Check if result is an image or a file path
51
  if isinstance(result, str): # Assuming result might be a file path
52
  if os.path.exists(result):
 
67
  def home():
68
  prompt = request.args.get('prompt', '')
69
  model = request.args.get('model', default_models[0] if default_models else 'NA')
70
+ negative_prompt = request.args.get('Nprompt', None)
71
 
72
  if not model or model not in models_load:
73
  return f'Invalid model: {model}', 400
74
 
75
  if prompt:
76
  # Generate the image
77
+ image = gen_fn(model, prompt, negative_prompt)
78
  if isinstance(image, Image.Image): # Ensure the result is a PIL image
79
  # Save image to BytesIO object
80
  img_io = BytesIO()
 
86
 
87
  if __name__ == '__main__':
88
  # Launch Flask app
89
+ app.run(host='0.0.0.0', port=7860) # Run Flask app