Syed-Hasan-8503
commited on
Commit
•
e8f388d
1
Parent(s):
6be9da6
App files
Browse files- app.py +41 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import replicate
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
api = replicate.Client(api_token="r8_9BTRdfQjCrVHkVMyQ6xAYJS52S6mLzx4YP6VA")
|
8 |
+
|
9 |
+
# Setting up Replicate AI API for stable diffusion
|
10 |
+
def generate_image(input_text, width=768, height=768, guidance_scale=7.5, num_inference_steps=50):
|
11 |
+
guidance_scale = float(guidance_scale)
|
12 |
+
output = api.run(
|
13 |
+
"stability-ai/stable-diffusion:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
|
14 |
+
input={
|
15 |
+
"width": width,
|
16 |
+
"height": height,
|
17 |
+
"prompt": input_text,
|
18 |
+
"scheduler": "K_EULER",
|
19 |
+
"num_outputs": 1,
|
20 |
+
"guidance_scale": guidance_scale,
|
21 |
+
"num_inference_steps": num_inference_steps
|
22 |
+
}
|
23 |
+
)
|
24 |
+
|
25 |
+
image_url = output[0]
|
26 |
+
response = requests.get(image_url)
|
27 |
+
image = Image.open(BytesIO(response.content))
|
28 |
+
return image
|
29 |
+
|
30 |
+
# Setting up a gradio interface
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=generate_image,
|
34 |
+
inputs=[gr.Textbox(label="Prompt"),
|
35 |
+
gr.Slider(label="Width", minimum = 64, maximum = 768, step = 64),
|
36 |
+
gr.Slider(label="Height", minimum = 64, maximum = 768, step = 64),
|
37 |
+
gr.Slider(label="Guidance Scale", minimum = 0, maximum = 20, step = 0.5),
|
38 |
+
gr.Radio([10,20,30,40,50], label="Inference Steps", info="Choose the number of Inference Steps")],
|
39 |
+
outputs="image")
|
40 |
+
|
41 |
+
iface.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
replicate
|
2 |
+
gradio
|