Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import google.generativeai as genai
|
3 |
import requests
|
|
|
4 |
|
5 |
# List of popular styles
|
6 |
STYLES = [
|
@@ -63,24 +64,23 @@ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt):
|
|
63 |
"height": 1024,
|
64 |
"num_images": 1,
|
65 |
"steps": 30,
|
66 |
-
"cfg_scale": 7.5
|
|
|
|
|
67 |
}
|
68 |
|
69 |
response = requests.post(url, json=payload, headers=headers)
|
70 |
|
71 |
if response.status_code == 200:
|
72 |
image_data = response.json()['images'][0]['image_base64']
|
73 |
-
return
|
74 |
else:
|
75 |
-
|
76 |
|
77 |
-
def
|
78 |
enhanced_prompt = enhance_prompt(google_api_key, prompt, style)
|
79 |
-
|
80 |
-
|
81 |
-
def generate_from_enhanced(stability_api_key, enhanced_prompt, style, negative_prompt):
|
82 |
-
image_url = generate_image(stability_api_key, enhanced_prompt, style, negative_prompt)
|
83 |
-
return image_url
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.Markdown("# Stability AI Image Generator with Google Gemini Prompt Enhancement")
|
@@ -92,25 +92,16 @@ with gr.Blocks() as demo:
|
|
92 |
prompt = gr.Textbox(label="Prompt")
|
93 |
style = gr.Dropdown(label="Style", choices=STYLES)
|
94 |
negative_prompt = gr.Textbox(label="Negative Prompt", value=DEFAULT_NEGATIVE_PROMPT)
|
95 |
-
|
96 |
-
generate_btn = gr.Button("Generate Image")
|
97 |
|
98 |
with gr.Column(scale=1):
|
99 |
image_output = gr.Image(label="Generated Image")
|
100 |
enhanced_prompt_output = gr.Textbox(label="Enhanced Prompt")
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
inputs=[google_api_key, prompt, style],
|
107 |
-
outputs=[enhanced_prompt_output, enhanced_prompt_state]
|
108 |
-
)
|
109 |
-
|
110 |
-
generate_btn.click(
|
111 |
-
generate_from_enhanced,
|
112 |
-
inputs=[stability_api_key, enhanced_prompt_state, style, negative_prompt],
|
113 |
-
outputs=[image_output]
|
114 |
)
|
115 |
|
116 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import google.generativeai as genai
|
3 |
import requests
|
4 |
+
import base64
|
5 |
|
6 |
# List of popular styles
|
7 |
STYLES = [
|
|
|
64 |
"height": 1024,
|
65 |
"num_images": 1,
|
66 |
"steps": 30,
|
67 |
+
"cfg_scale": 7.5,
|
68 |
+
"seed": 0,
|
69 |
+
"output_format": "png"
|
70 |
}
|
71 |
|
72 |
response = requests.post(url, json=payload, headers=headers)
|
73 |
|
74 |
if response.status_code == 200:
|
75 |
image_data = response.json()['images'][0]['image_base64']
|
76 |
+
return base64.b64decode(image_data)
|
77 |
else:
|
78 |
+
raise Exception(f"Image generation failed: {response.text}")
|
79 |
|
80 |
+
def process_and_generate(google_api_key, stability_api_key, prompt, style, negative_prompt):
|
81 |
enhanced_prompt = enhance_prompt(google_api_key, prompt, style)
|
82 |
+
image_data = generate_image(stability_api_key, enhanced_prompt, style, negative_prompt)
|
83 |
+
return image_data, enhanced_prompt
|
|
|
|
|
|
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.Markdown("# Stability AI Image Generator with Google Gemini Prompt Enhancement")
|
|
|
92 |
prompt = gr.Textbox(label="Prompt")
|
93 |
style = gr.Dropdown(label="Style", choices=STYLES)
|
94 |
negative_prompt = gr.Textbox(label="Negative Prompt", value=DEFAULT_NEGATIVE_PROMPT)
|
95 |
+
submit_btn = gr.Button("Generate Image")
|
|
|
96 |
|
97 |
with gr.Column(scale=1):
|
98 |
image_output = gr.Image(label="Generated Image")
|
99 |
enhanced_prompt_output = gr.Textbox(label="Enhanced Prompt")
|
100 |
|
101 |
+
submit_btn.click(
|
102 |
+
process_and_generate,
|
103 |
+
inputs=[google_api_key, stability_api_key, prompt, style, negative_prompt],
|
104 |
+
outputs=[image_output, enhanced_prompt_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
)
|
106 |
|
107 |
demo.launch()
|