Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,8 @@ import streamlit as st
|
|
| 2 |
from io import BytesIO
|
| 3 |
import base64
|
| 4 |
import os
|
| 5 |
-
from PIL import Image
|
| 6 |
from replicate import Client
|
| 7 |
-
|
| 8 |
|
| 9 |
illuse = Client(api_token=os.getenv('REPLICATE'))
|
| 10 |
model_name = "andreasjansson/illusion:75d51a73fce3c00de31ed9ab4358c73e8fc0f627dc8ce975818e653317cb919b"
|
|
@@ -13,36 +12,37 @@ example_image = "https://replicate.delivery/pbxt/hHJNV9QteKX8DK2ckkUeXsqbEIKNGFX
|
|
| 13 |
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):
|
| 14 |
try:
|
| 15 |
inputs = {
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
if pattern_image is not None:
|
| 30 |
image = Image.open(pattern_image)
|
| 31 |
image_bytes = BytesIO()
|
| 32 |
image.save(image_bytes, format='PNG')
|
| 33 |
inputs['image'] = image_bytes
|
| 34 |
|
| 35 |
-
|
| 36 |
model_name,
|
| 37 |
input=inputs
|
| 38 |
)
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
print(e)
|
| 42 |
st.error(str(e))
|
| 43 |
return
|
| 44 |
|
| 45 |
-
|
| 46 |
st.title("Illusion Diffusion Fast Demo powered by replicate")
|
| 47 |
|
| 48 |
prompt = st.text_input("Prompt")
|
|
@@ -65,9 +65,9 @@ border = st.slider("border", min_value=0, max_value=4, step=1, value=4)
|
|
| 65 |
qrcode_background = st.selectbox("qrcode_background", options=['gray', 'white'], index=1)
|
| 66 |
|
| 67 |
if st.button("Run"):
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
st.image(
|
| 71 |
-
|
| 72 |
|
| 73 |
st.image(example_image, caption='Example Image', use_column_width=True)
|
|
|
|
|
|
| 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"
|
|
|
|
| 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 Fast Demo powered by replicate")
|
| 47 |
|
| 48 |
prompt = st.text_input("Prompt")
|
|
|
|
| 65 |
qrcode_background = st.selectbox("qrcode_background", options=['gray', 'white'], index=1)
|
| 66 |
|
| 67 |
if st.button("Run"):
|
| 68 |
+
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)
|
| 69 |
+
for uri in result_uris:
|
| 70 |
+
st.image(uri)
|
|
|
|
| 71 |
|
| 72 |
st.image(example_image, caption='Example Image', use_column_width=True)
|
| 73 |
+
st.markdown("powered with ❤️ by aiconvert")
|