Spaces:
Runtime error
Runtime error
mikaelbhai
commited on
Commit
·
1cfd147
1
Parent(s):
6c6d4f6
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
api_key = 'sk-CED85fi0ZhUDMWg4GvFQ5k53o7yoL7WOaPyPQcb8zPi7eDGi' # your Stability AI API key
|
9 |
+
|
10 |
+
def stable_diffusion(user_input):
|
11 |
+
prompt = user_input
|
12 |
+
print("Prompt:", prompt)
|
13 |
+
|
14 |
+
# Create the Stable Difusion image using the Stability AI API
|
15 |
+
response = requests.post(
|
16 |
+
'https://api.stability.ai/v1/image/generate',
|
17 |
+
headers={'Authorization': f'Bearer {api_key}'},
|
18 |
+
json={
|
19 |
+
'text': prompt,
|
20 |
+
'model': 'sd-c2',
|
21 |
+
'steps': 200,
|
22 |
+
'size': 512,
|
23 |
+
'start_size': 64,
|
24 |
+
'start_scale': 1,
|
25 |
+
'end_scale': 0.25,
|
26 |
+
'deterministic': False,
|
27 |
+
'clip': False,
|
28 |
+
'top_k': 0,
|
29 |
+
'top_p': 1,
|
30 |
+
'temperature': 1,
|
31 |
+
'seed': None,
|
32 |
+
'noise_seed': None,
|
33 |
+
}
|
34 |
+
)
|
35 |
+
response.raise_for_status()
|
36 |
+
|
37 |
+
# Convert the image to a format that Gradio can display
|
38 |
+
img_bytes = io.BytesIO(response.content)
|
39 |
+
img = Image.open(img_bytes)
|
40 |
+
img_arr = np.array(img)
|
41 |
+
|
42 |
+
return img_arr
|
43 |
+
|
44 |
+
iface = gr.Interface(fn=stable_diffusion, inputs="text", outputs="image", title="bhAI (text to image)")
|
45 |
+
iface.launch()
|