|
import gradio as gr |
|
import requests |
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
|
|
API_KEY = "5afe345e-57fd-4fd7-8a77-d06ce59f07ad" |
|
DEEP_AI_URL = "https://api.deepai.org/api/text2img" |
|
|
|
def generate_image(prompt): |
|
|
|
data = { |
|
'text': prompt, |
|
'api_key': API_KEY, |
|
} |
|
|
|
|
|
response = requests.post(DEEP_AI_URL, data=data) |
|
|
|
|
|
if response.status_code == 200: |
|
|
|
response_data = response.json() |
|
image_url = response_data['output_url'] |
|
|
|
|
|
image_response = requests.get(image_url) |
|
image = Image.open(BytesIO(image_response.content)) |
|
|
|
|
|
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) |