Sean Laurent
commited on
Commit
·
d27a72c
1
Parent(s):
43e76e1
Added app.py
Browse files- app.py +47 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import banana_dev as banana
|
| 2 |
+
import base64
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
api_key = "1a3e1402-a0ce-4e5f-beb2-0437bc244f7b"
|
| 8 |
+
model_key = "72127aef-ae0b-4a69-bee5-ed7ffda1ea04"
|
| 9 |
+
|
| 10 |
+
model_inputs = {
|
| 11 |
+
"endpoint": "txt2img",
|
| 12 |
+
"params": {
|
| 13 |
+
"prompt": "",
|
| 14 |
+
"negative_prompt": "",
|
| 15 |
+
"steps": 25,
|
| 16 |
+
"sampler_name": "Euler a",
|
| 17 |
+
"cfg_scale": 7.5,
|
| 18 |
+
"seed": 42,
|
| 19 |
+
"batch_size": 1,
|
| 20 |
+
"n_iter": 1,
|
| 21 |
+
"width": 768,
|
| 22 |
+
"height": 768,
|
| 23 |
+
"tiling": False
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
def stable_diffusion_txt2img(prompt, api_key, model_key, model_inputs):
|
| 28 |
+
# Update the model_inputs with the provided prompt
|
| 29 |
+
model_inputs["params"]["prompt"] = prompt
|
| 30 |
+
|
| 31 |
+
# Run the model
|
| 32 |
+
out = banana.run(api_key, model_key, model_inputs)
|
| 33 |
+
|
| 34 |
+
# Process the output
|
| 35 |
+
image_byte_string = out["modelOutputs"][0]["images"]
|
| 36 |
+
image_encoded = image_byte_string[0].encode("utf-8")
|
| 37 |
+
image_bytes = BytesIO(base64.b64decode(image_encoded))
|
| 38 |
+
image = Image.open(image_bytes)
|
| 39 |
+
return image
|
| 40 |
+
|
| 41 |
+
# Gradio Interface
|
| 42 |
+
def generator(prompt):
|
| 43 |
+
generated_image = stable_diffusion_txt2img(prompt, api_key, model_key, model_inputs)
|
| 44 |
+
return generated_image
|
| 45 |
+
|
| 46 |
+
iface = gr.Interface(fn=generator, inputs="text", outputs="image")
|
| 47 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
banana_dev==4.0.2
|
| 2 |
+
gradio==3.27.0
|
| 3 |
+
Pillow==9.5.0
|
| 4 |
+
Pillow==9.5.0
|