File size: 1,350 Bytes
3cab89c 8c00444 16cf6ae 3cab89c e4a760a 16cf6ae e4a760a 16cf6ae e4a760a |
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 42 43 |
import gradio as gr
import requests
from PIL import Image
from io import BytesIO
# Replace 'YOUR_API_KEY' with your actual DeepAI API key
API_KEY = "5afe345e-57fd-4fd7-8a77-d06ce59f07ad"
DEEP_AI_URL = "https://api.deepai.org/api/text2img"
def generate_image(prompt):
# Set up the API request parameters
data = {
'text': prompt,
'api_key': API_KEY,
}
# Make the request to the DeepAI API
response = requests.post(DEEP_AI_URL, data=data)
# Check if the request was successful
if response.status_code == 200:
# Parse the response to get the image URL or binary data
response_data = response.json()
image_url = response_data['output_url']
# For the sake of this example, we assume the image URL is directly downloadable
image_response = requests.get(image_url)
image = Image.open(BytesIO(image_response.content))
# Convert the image to a format that Gradio can display
return image
else:
return "Error generating image"
iface = gr.Interface(
fn=generate_image,
inputs=gr.inputs.Text(label="Enter a prompt"),
outputs=gr.outputs.Image(type="auto", label="Generated Image"),
title="AI Image Generator",
description="Enter a text prompt to generate an image."
)
iface.launch(share=True) |