bluenevus commited on
Commit
9254c71
·
verified ·
1 Parent(s): da0ae75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -59,10 +59,8 @@ app.layout = dbc.Container([
59
  ],
60
  value="1:1"
61
  ),
62
- dbc.Label("CFG Scale"),
63
- dcc.Slider(id="cfg-scale", min=1, max=10, step=0.1, value=4, marks={1: '1', 5: '5', 10: '10'}),
64
  dbc.Label("Steps"),
65
- dcc.Slider(id="steps", min=4, max=50, step=1, value=30, marks={4: '4', 25: '25', 50: '50'}),
66
  ],
67
  title="Advanced Settings",
68
  ),
@@ -95,17 +93,17 @@ def enhance_prompt(google_api_key, prompt, style):
95
  genai.configure(api_key=google_api_key)
96
  model = genai.GenerativeModel("gemini-2.0-flash-lite")
97
  enhanced_prompt_request = f"""
98
- Task: Enhance the following prompt for high-quality, realistic image generation.
99
  Style: {style}
100
  Original prompt: '{prompt}'
101
 
102
  Instructions:
103
  1. Expand the prompt to be more detailed, vivid, and realistic with camera used and the setting for that camera like ISO etc.
104
- 2. Incorporate elements of the specified style, focusing on realism and natural appearances.
105
- 3. Add details that enhance the realism of the scene, especially for elements like trees, textures, and lighting.
106
- 4. Emphasize natural lighting and enhance the realism of textures and colors.
107
  5. Avoid terms that might result in artificial or cartoonish appearance unless specified by user.
108
- 6. Maintain the original intent of the prompt while significantly improving its descriptive quality.
109
  7. Provide ONLY the enhanced prompt, without any explanations or options.
110
  8. Keep the enhanced prompt concise, ideally under 100 words.
111
 
@@ -128,7 +126,7 @@ def enhance_prompt(google_api_key, prompt, style):
128
  logging.error(f"Error in enhance_prompt: {str(e)}")
129
  raise
130
 
131
- def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt, cfg_scale=7, steps=30, aspect_ratio="1:1"):
132
  url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
133
 
134
  headers = {
@@ -137,13 +135,13 @@ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt, c
137
  }
138
 
139
  data = {
140
- "prompt": f"{enhanced_prompt}, Style: {style}, highly detailed, photorealistic, high quality, natural lighting, realistic textures and colors",
141
  "negative_prompt": negative_prompt,
142
  "model": "sd3.5-large-turbo",
143
  "output_format": "jpeg",
144
  "num_images": 1,
145
  "steps": steps,
146
- # "cfg_scale": cfg_scale,
147
  "style_preset": style,
148
  "aspect_ratio": aspect_ratio,
149
  }
@@ -169,7 +167,7 @@ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt, c
169
  logging.error(f"Request failed: {str(e)}")
170
  raise Exception(f"Request failed: {str(e)}")
171
 
172
- def process_and_generate(google_api_key, stability_api_key, prompt, style, cfg_scale, steps, aspect_ratio, set_status):
173
  try:
174
  set_status("Enhancing prompt...")
175
  enhanced_prompt = enhance_prompt(google_api_key, prompt, style)
@@ -178,7 +176,7 @@ def process_and_generate(google_api_key, stability_api_key, prompt, style, cfg_s
178
  max_attempts = 3
179
  for attempt in range(max_attempts):
180
  try:
181
- image_bytes = generate_image(stability_api_key, enhanced_prompt, style, DEFAULT_NEGATIVE_PROMPT, cfg_scale, steps, aspect_ratio)
182
  set_status("Image generated successfully!")
183
  return image_bytes, enhanced_prompt
184
  except Exception as e:
 
59
  ],
60
  value="1:1"
61
  ),
 
 
62
  dbc.Label("Steps"),
63
+ dcc.Slider(id="steps", min=4, max=50, step=1, value=20, marks={4: '4', 25: '25', 50: '50'}),
64
  ],
65
  title="Advanced Settings",
66
  ),
 
93
  genai.configure(api_key=google_api_key)
94
  model = genai.GenerativeModel("gemini-2.0-flash-lite")
95
  enhanced_prompt_request = f"""
96
+ Task: Enhance the following prompt with details to match the specified style
97
  Style: {style}
98
  Original prompt: '{prompt}'
99
 
100
  Instructions:
101
  1. Expand the prompt to be more detailed, vivid, and realistic with camera used and the setting for that camera like ISO etc.
102
+ 2. Incorporate elements of the specified style.
103
+ 3. Add details that enhance the scene to the specified style
104
+ 4. Emphasize natural lighting and enhance the realism of textures and colors based on the specified style.
105
  5. Avoid terms that might result in artificial or cartoonish appearance unless specified by user.
106
+ 6. Maintain the original intent of the prompt while significantly improving its descriptive quality with details.
107
  7. Provide ONLY the enhanced prompt, without any explanations or options.
108
  8. Keep the enhanced prompt concise, ideally under 100 words.
109
 
 
126
  logging.error(f"Error in enhance_prompt: {str(e)}")
127
  raise
128
 
129
+ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt, steps=30, aspect_ratio="1:1"):
130
  url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
131
 
132
  headers = {
 
135
  }
136
 
137
  data = {
138
+ "prompt": f"{enhanced_prompt}, Style: {style}, highly detailed, high quality, descriptive",
139
  "negative_prompt": negative_prompt,
140
  "model": "sd3.5-large-turbo",
141
  "output_format": "jpeg",
142
  "num_images": 1,
143
  "steps": steps,
144
+ "cfg_scale": 7, # Default value
145
  "style_preset": style,
146
  "aspect_ratio": aspect_ratio,
147
  }
 
167
  logging.error(f"Request failed: {str(e)}")
168
  raise Exception(f"Request failed: {str(e)}")
169
 
170
+ def process_and_generate(google_api_key, stability_api_key, prompt, style, steps, aspect_ratio, set_status):
171
  try:
172
  set_status("Enhancing prompt...")
173
  enhanced_prompt = enhance_prompt(google_api_key, prompt, style)
 
176
  max_attempts = 3
177
  for attempt in range(max_attempts):
178
  try:
179
+ image_bytes = generate_image(stability_api_key, enhanced_prompt, style, DEFAULT_NEGATIVE_PROMPT, steps, aspect_ratio)
180
  set_status("Image generated successfully!")
181
  return image_bytes, enhanced_prompt
182
  except Exception as e: