Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
import base64
|
| 4 |
+
import os
|
| 5 |
+
from replicate import Client
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
illuse = Client(api_token=os.getenv('REPLICATE'))
|
| 9 |
+
model_name = "andreasjansson/illusion:75d51a73fce3c00de31ed9ab4358c73e8fc0f627dc8ce975818e653317cb919b"
|
| 10 |
+
example_image = "https://replicate.delivery/pbxt/hHJNV9QteKX8DK2ckkUeXsqbEIKNGFXU1fN0MJoizz3iPlOjA/output-0.png"
|
| 11 |
+
|
| 12 |
+
def generate(prompt, negative_prompt, qr_content, pattern_image, num_inference_steps, guidance_scale, width, height, seed, num_outputs, controlnet_conditioning_scale, border, qrcode_background):
|
| 13 |
+
try:
|
| 14 |
+
inputs = {
|
| 15 |
+
'prompt': prompt,
|
| 16 |
+
'negative_prompt': negative_prompt,
|
| 17 |
+
'qr_code_content': qr_content,
|
| 18 |
+
'num_inference_steps': num_inference_steps,
|
| 19 |
+
'guidance_scale': guidance_scale,
|
| 20 |
+
'width': width,
|
| 21 |
+
'height': height,
|
| 22 |
+
'seed': seed,
|
| 23 |
+
'num_outputs': num_outputs,
|
| 24 |
+
'controlnet_conditioning_scale': controlnet_conditioning_scale,
|
| 25 |
+
'border': border,
|
| 26 |
+
'qrcode_background': qrcode_background
|
| 27 |
+
}
|
| 28 |
+
if pattern_image is not None:
|
| 29 |
+
image = Image.open(pattern_image)
|
| 30 |
+
image_bytes = BytesIO()
|
| 31 |
+
image.save(image_bytes, format='PNG')
|
| 32 |
+
inputs['image'] = image_bytes
|
| 33 |
+
|
| 34 |
+
result_uris = illuse.run(
|
| 35 |
+
model_name,
|
| 36 |
+
input=inputs
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
return result_uris
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(e)
|
| 43 |
+
st.error(str(e))
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
st.title("Illusion Diffusion by Aiconvert.online")
|
| 47 |
+
st.markdown('<style>h1{color: #191970; text-align: center;}</style>', unsafe_allow_html=True)
|
| 48 |
+
|
| 49 |
+
prompt = st.text_input("Prompt")
|
| 50 |
+
negative_prompt = st.text_input("Negative")
|
| 51 |
+
|
| 52 |
+
qr_content = st.text_input("QR Code Content", "https://youtube.com/")
|
| 53 |
+
pattern_input = st.file_uploader("Pattern Image (if used, QR Code Content won't be used)", type=["jpg", "png", "jpeg"])
|
| 54 |
+
|
| 55 |
+
st.sidebar.markdown("## Advanced Settings")
|
| 56 |
+
|
| 57 |
+
with st.sidebar.expander("Advanced Settings", expanded=True):
|
| 58 |
+
num_inference_steps = st.slider("num_inference_steps", min_value=20, max_value=100, step=1, value=42)
|
| 59 |
+
guidance_scale = st.slider("guidance_scale", min_value=0.1, max_value=30.0, step=0.01, value=14.5)
|
| 60 |
+
width = st.slider("width", min_value=128, max_value=1024, step=8, value=768)
|
| 61 |
+
height = st.slider("height", min_value=128, max_value=1024, step=8, value=768)
|
| 62 |
+
seed = st.number_input("seed", value=-1)
|
| 63 |
+
num_outputs = st.slider("num_outputs", min_value=1, max_value=4, step=1, value=1)
|
| 64 |
+
controlnet_conditioning_scale = st.slider("controlnet_conditioning_scale", min_value=0, max_value=4, step=1, value=1)
|
| 65 |
+
border = st.slider("border", min_value=0, max_value=4, step=1, value=4)
|
| 66 |
+
qrcode_background = st.selectbox("qrcode_background", options=['gray', 'white'], index=1)
|
| 67 |
+
|
| 68 |
+
if st.button("Generate"):
|
| 69 |
+
with st.spinner("Running..."):
|
| 70 |
+
result_uris = generate(prompt, negative_prompt, qr_content, pattern_input, num_inference_steps, guidance_scale, width, height, seed, num_outputs, controlnet_conditioning_scale, border, qrcode_background)
|
| 71 |
+
for uri in result_uris:
|
| 72 |
+
st.image(uri)
|
| 73 |
+
|
| 74 |
+
st.image(example_image, caption='Example Image', use_column_width=True)
|
| 75 |
+
st.markdown("powered with ❤️ by Aiconvert.online")
|