Buildings / app.py
techasad's picture
Update app.py
90a5090
raw
history blame
1.06 kB
import gradio as gr
import requests
from PIL import Image
import io
import PIL
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
headers = {"Authorization": "Bearer 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"}
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()