Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,7 @@ def enhance_prompt(google_api_key, prompt, style):
|
|
56 |
raise
|
57 |
|
58 |
def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt):
|
59 |
-
url = "https://api.stability.ai/v2beta/stable-image/generate/
|
60 |
|
61 |
headers = {
|
62 |
"Accept": "image/*",
|
@@ -66,7 +66,12 @@ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt):
|
|
66 |
data = {
|
67 |
"prompt": f"{enhanced_prompt}, Style: {style}",
|
68 |
"negative_prompt": negative_prompt,
|
69 |
-
"
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
try:
|
@@ -93,23 +98,23 @@ def process_and_generate(google_api_key, stability_api_key, prompt, style, negat
|
|
93 |
image_bytes = generate_image(stability_api_key, enhanced_prompt, style, negative_prompt)
|
94 |
|
95 |
# Save image to a file
|
96 |
-
with open("generated_image.
|
97 |
f.write(image_bytes)
|
98 |
|
99 |
# Return the file path and enhanced prompt
|
100 |
-
return "generated_image.
|
101 |
except Exception as e:
|
102 |
logging.error(f"Error in process_and_generate: {str(e)}")
|
103 |
return str(e), enhanced_prompt if 'enhanced_prompt' in locals() else "Error occurred before prompt enhancement"
|
104 |
|
105 |
with gr.Blocks() as demo:
|
106 |
-
gr.Markdown("# Stability AI
|
107 |
|
108 |
with gr.Row():
|
109 |
with gr.Column(scale=1):
|
110 |
google_api_key = gr.Textbox(label="Google AI API Key", type="password")
|
111 |
stability_api_key = gr.Textbox(label="Stability AI API Key", type="password")
|
112 |
-
prompt = gr.Textbox(label="
|
113 |
style = gr.Dropdown(label="Style", choices=STYLES)
|
114 |
negative_prompt = gr.Textbox(label="Negative Prompt", value=DEFAULT_NEGATIVE_PROMPT)
|
115 |
submit_btn = gr.Button("Generate Image")
|
|
|
56 |
raise
|
57 |
|
58 |
def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt):
|
59 |
+
url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
|
60 |
|
61 |
headers = {
|
62 |
"Accept": "image/*",
|
|
|
66 |
data = {
|
67 |
"prompt": f"{enhanced_prompt}, Style: {style}",
|
68 |
"negative_prompt": negative_prompt,
|
69 |
+
"model": "sd3.5-large-turbo",
|
70 |
+
"output_format": "jpeg",
|
71 |
+
"width": 1024,
|
72 |
+
"height": 1024,
|
73 |
+
"num_images": 1,
|
74 |
+
"steps": 4, # SD3.5 Large Turbo generates high-quality images in just 4 steps
|
75 |
}
|
76 |
|
77 |
try:
|
|
|
98 |
image_bytes = generate_image(stability_api_key, enhanced_prompt, style, negative_prompt)
|
99 |
|
100 |
# Save image to a file
|
101 |
+
with open("generated_image.jpeg", "wb") as f:
|
102 |
f.write(image_bytes)
|
103 |
|
104 |
# Return the file path and enhanced prompt
|
105 |
+
return "generated_image.jpeg", enhanced_prompt
|
106 |
except Exception as e:
|
107 |
logging.error(f"Error in process_and_generate: {str(e)}")
|
108 |
return str(e), enhanced_prompt if 'enhanced_prompt' in locals() else "Error occurred before prompt enhancement"
|
109 |
|
110 |
with gr.Blocks() as demo:
|
111 |
+
gr.Markdown("# Stability AI SD3.5 Large Turbo Image Generator with Google Gemini Prompt Enhancement")
|
112 |
|
113 |
with gr.Row():
|
114 |
with gr.Column(scale=1):
|
115 |
google_api_key = gr.Textbox(label="Google AI API Key", type="password")
|
116 |
stability_api_key = gr.Textbox(label="Stability AI API Key", type="password")
|
117 |
+
prompt = gr.Textbox(label="Prompt")
|
118 |
style = gr.Dropdown(label="Style", choices=STYLES)
|
119 |
negative_prompt = gr.Textbox(label="Negative Prompt", value=DEFAULT_NEGATIVE_PROMPT)
|
120 |
submit_btn = gr.Button("Generate Image")
|