Spaces:
Running
Running
File size: 1,145 Bytes
f14a738 b8dbbd0 f14a738 3024a38 a2e463e b8dbbd0 f14a738 90a5090 f14a738 |
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 44 45 46 |
import gradio as gr
import requests
from PIL import Image
import io
import PIL
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
headers = os.getenv("SEECRET_TOKEN")
def generate_image(prompt):
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
if response.status_code == 200:
image_bytes = response.content
try:
image = Image.open(io.BytesIO(image_bytes))
return image
except PIL.UnidentifiedImageError as e:
return None
else:
return None
iface = gr.Interface(
fn=generate_image,
inputs="text",
outputs="image",
title="🌄 Prompt to Image Generator 🌄",
description="Generate stunning images from your prompts using an AI model.",
layout="wide",
theme="huggingface",
examples=[
["A surreal painting of a floating city at sunset"],
["An abstract landscape with vibrant colors and geometric shapes"]
]
)
iface.launch()
|