Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import os
|
| 5 |
+
from getpass import getpass
|
| 6 |
+
from replicate import replicate
|
| 7 |
+
from IPython.display import Image
|
| 8 |
+
|
| 9 |
+
# Set up Replicate API token
|
| 10 |
+
st.title('Stable Diffusion 3 Image Generation')
|
| 11 |
+
|
| 12 |
+
if 'REPLICATE_API_TOKEN' not in os.environ:
|
| 13 |
+
st.warning('Please set your Replicate API token. You can obtain it from https://replicate.com/account.')
|
| 14 |
+
REPLICATE_API_TOKEN = st.text_input('Enter your Replicate API token:')
|
| 15 |
+
if REPLICATE_API_TOKEN:
|
| 16 |
+
os.environ["REPLICATE_API_TOKEN"] = REPLICATE_API_TOKEN
|
| 17 |
+
else:
|
| 18 |
+
st.write('API token is set.')
|
| 19 |
+
|
| 20 |
+
# Function to generate image
|
| 21 |
+
@st.cache(allow_output_mutation=True)
|
| 22 |
+
def generate_image():
|
| 23 |
+
output = replicate.run(
|
| 24 |
+
"stability-ai/stable-diffusion-3",
|
| 25 |
+
input={
|
| 26 |
+
"cfg": 4.5,
|
| 27 |
+
"prompt": "a photo of vibrant artistic graffiti on a wall saying \"SD3 medium\"",
|
| 28 |
+
"aspect_ratio": "3:2",
|
| 29 |
+
"output_format": "webp",
|
| 30 |
+
"output_quality": 79,
|
| 31 |
+
"negative_prompt": "ugly, distorted"
|
| 32 |
+
}
|
| 33 |
+
)
|
| 34 |
+
return output[0]
|
| 35 |
+
|
| 36 |
+
# Main Streamlit app
|
| 37 |
+
def main():
|
| 38 |
+
st.subheader('Generate Image')
|
| 39 |
+
if 'REPLICATE_API_TOKEN' in os.environ:
|
| 40 |
+
image_url = generate_image()
|
| 41 |
+
st.image(image_url)
|
| 42 |
+
else:
|
| 43 |
+
st.warning('Please set your Replicate API token to generate an image.')
|
| 44 |
+
|
| 45 |
+
if __name__ == '__main__':
|
| 46 |
+
main()
|