Spaces:
Sleeping
Sleeping
MackinationsAi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -41,9 +41,9 @@ def generate_image(api_key, prompt, aspect_ratio, mode, model, seed, output_form
|
|
41 |
files=files,
|
42 |
data=data
|
43 |
)
|
|
|
44 |
return response
|
45 |
|
46 |
-
# Streamlit Ui
|
47 |
def main():
|
48 |
st.image("static/SD3_webui_logo_image.png", use_column_width=True)
|
49 |
|
@@ -53,6 +53,10 @@ def main():
|
|
53 |
st.session_state.prompt = ""
|
54 |
if 'negative_prompt' not in st.session_state:
|
55 |
st.session_state.negative_prompt = ""
|
|
|
|
|
|
|
|
|
56 |
|
57 |
api_key = st.text_input("Enter your API key:", type="password", value=st.session_state.api_key)
|
58 |
models = st.selectbox("Select model:", ["sd3", "sd3-turbo"], index=0)
|
@@ -74,18 +78,18 @@ def main():
|
|
74 |
with st.spinner('Generating Image...'):
|
75 |
result = generate_image(api_key, prompt, aspect_ratios, mode, models, seed, output_formats, strength, negative_prompt, uploaded_file)
|
76 |
if result.status_code == 200:
|
77 |
-
|
78 |
-
st.
|
79 |
-
|
80 |
-
|
81 |
-
image.save(file_path)
|
82 |
-
st.success(f'Image saved to {file_path}')
|
83 |
-
# Download generated image for Huggingface Spaces add-on
|
84 |
-
with open(file_path, "rb") as file:
|
85 |
-
st.download_button(label=":green[Download Image]", data=file, file_name=file_path, mime=f"image/{output_formats}", use_container_width=True)
|
86 |
else:
|
87 |
st.error('Failed to generate image: ' + str(result.json()))
|
88 |
|
|
|
|
|
|
|
|
|
|
|
89 |
with st.sidebar:
|
90 |
st.link_button("Stability.Ai _ API Documentation", "https://platform.stability.ai/docs/api-reference", use_container_width=True)
|
91 |
with st.expander("Image Generation Costs", expanded=True):
|
@@ -98,6 +102,6 @@ def main():
|
|
98 |
Credits cost $10 per 1,000 credits, which is enough credits for roughly 154 SD3 images or 250 SD3 Turbo images.
|
99 |
""")
|
100 |
st.link_button("Account_Page", "https://platform.stability.ai/account/credits", use_container_width=True)
|
101 |
-
|
102 |
if __name__ == "__main__":
|
103 |
main()
|
|
|
41 |
files=files,
|
42 |
data=data
|
43 |
)
|
44 |
+
|
45 |
return response
|
46 |
|
|
|
47 |
def main():
|
48 |
st.image("static/SD3_webui_logo_image.png", use_column_width=True)
|
49 |
|
|
|
53 |
st.session_state.prompt = ""
|
54 |
if 'negative_prompt' not in st.session_state:
|
55 |
st.session_state.negative_prompt = ""
|
56 |
+
if 'image_data' not in st.session_state:
|
57 |
+
st.session_state.image_data = None
|
58 |
+
if 'image_path' not in st.session_state:
|
59 |
+
st.session_state.image_path = None
|
60 |
|
61 |
api_key = st.text_input("Enter your API key:", type="password", value=st.session_state.api_key)
|
62 |
models = st.selectbox("Select model:", ["sd3", "sd3-turbo"], index=0)
|
|
|
78 |
with st.spinner('Generating Image...'):
|
79 |
result = generate_image(api_key, prompt, aspect_ratios, mode, models, seed, output_formats, strength, negative_prompt, uploaded_file)
|
80 |
if result.status_code == 200:
|
81 |
+
st.session_state.image_data = Image.open(io.BytesIO(result.content))
|
82 |
+
st.session_state.image_path = os.path.join(f"gen_{models}_{seed}_{time.strftime('%H.%M.%S').lower()}.{output_formats}")
|
83 |
+
st.session_state.image_data.save(st.session_state.image_path)
|
84 |
+
st.success(f'Image saved to {st.session_state.image_path}')
|
|
|
|
|
|
|
|
|
|
|
85 |
else:
|
86 |
st.error('Failed to generate image: ' + str(result.json()))
|
87 |
|
88 |
+
if st.session_state.image_data is not None:
|
89 |
+
st.image(st.session_state.image_data, use_column_width=True)
|
90 |
+
with open(st.session_state.image_path, "rb") as file:
|
91 |
+
st.download_button(label=":green[Download Image]", data=file, file_name=st.session_state.image_path, mime=f"image/{output_formats}", use_container_width=True)
|
92 |
+
|
93 |
with st.sidebar:
|
94 |
st.link_button("Stability.Ai _ API Documentation", "https://platform.stability.ai/docs/api-reference", use_container_width=True)
|
95 |
with st.expander("Image Generation Costs", expanded=True):
|
|
|
102 |
Credits cost $10 per 1,000 credits, which is enough credits for roughly 154 SD3 images or 250 SD3 Turbo images.
|
103 |
""")
|
104 |
st.link_button("Account_Page", "https://platform.stability.ai/account/credits", use_container_width=True)
|
105 |
+
|
106 |
if __name__ == "__main__":
|
107 |
main()
|