File size: 1,248 Bytes
1cfd147
42f7545
1cfd147
 
 
42f7545
09e61f6
42f7545
 
 
 
 
 
 
1cfd147
42f7545
 
 
 
 
 
 
 
 
 
 
 
1cfd147
 
42f7545
 
 
 
 
 
 
 
 
 
1cfd147
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
import gradio as gr
from PIL import Image
import numpy as np

# Replace with your Dream API key
api_key = 'sk-CED85fi0ZhUDMWg4GvFQ5k53o7yoL7WOaPyPQcb8zPi7eDGi'

def generate_image(prompt):
    # Set up the request headers
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }

    # Set up the request data
    data = {
        "model": "stable-diffusion",
        "prompt": prompt,
        "steps": 100,
        "batch_size": 1,
        "gamma": 0.99,
        "device": "cpu"
    }

    # Send the request to Dream's API
    response = requests.post("https://api.dream.co/stable-diffusion/generate", json=data, headers=headers)
    response.raise_for_status()

    # Extract the image URL from the response
    image_url = response.json()["data"][0]["url"]

    # Download and display the image using PIL and Gradio
    image_bytes = requests.get(image_url).content
    image = Image.open(io.BytesIO(image_bytes))
    image_arr = np.array(image)
    return image_arr

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.")
iface.launch()