Spaces:
Runtime error
Runtime error
Commit
·
42f7545
1
Parent(s):
284d585
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,40 @@
|
|
1 |
-
|
2 |
-
import gradio as gr
|
3 |
import requests
|
|
|
4 |
from PIL import Image
|
5 |
-
import io
|
6 |
import numpy as np
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
response.raise_for_status()
|
21 |
-
|
22 |
-
# Convert the image to a format that Gradio can display
|
23 |
-
img_bytes = io.BytesIO(response.content)
|
24 |
-
img = Image.open(img_bytes)
|
25 |
-
img_arr = np.array(img)
|
26 |
-
|
27 |
-
return img_arr
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
iface.launch()
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import gradio as gr
|
3 |
from PIL import Image
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
+
# Replace with your Dream API key
|
7 |
+
api_key = "YOUR_API_KEY_HERE"
|
8 |
+
|
9 |
+
def generate_image(prompt):
|
10 |
+
# Set up the request headers
|
11 |
+
headers = {
|
12 |
+
"Content-Type": "application/json",
|
13 |
+
"Authorization": f"Bearer {api_key}"
|
14 |
+
}
|
15 |
|
16 |
+
# Set up the request data
|
17 |
+
data = {
|
18 |
+
"model": "stable-diffusion",
|
19 |
+
"prompt": prompt,
|
20 |
+
"steps": 100,
|
21 |
+
"batch_size": 1,
|
22 |
+
"gamma": 0.99,
|
23 |
+
"device": "cpu"
|
24 |
+
}
|
25 |
+
|
26 |
+
# Send the request to Dream's API
|
27 |
+
response = requests.post("https://api.dream.co/stable-diffusion/generate", json=data, headers=headers)
|
28 |
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
# Extract the image URL from the response
|
31 |
+
image_url = response.json()["data"][0]["url"]
|
32 |
+
|
33 |
+
# Download and display the image using PIL and Gradio
|
34 |
+
image_bytes = requests.get(image_url).content
|
35 |
+
image = Image.open(io.BytesIO(image_bytes))
|
36 |
+
image_arr = np.array(image)
|
37 |
+
return image_arr
|
38 |
+
|
39 |
+
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", title="bhAI (text to image using Dream Studio's Stable Difusion)", description="Enter a prompt to generate an image.")
|
40 |
iface.launch()
|