Npc / app.py
WatchOutForMike's picture
v1
835cfeb
raw
history blame
2.35 kB
import gradio as gr
import requests
from PIL import Image
import io
import PIL
import os
# API configuration
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
headers = {"Authorization": f"Bearer {os.getenv('SEECRET_TOKEN')}"}
# Function to generate images
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:
return "Failed to load the image. Ensure the prompt is appropriate."
else:
return f"Error: {response.status_code}. Unable to generate the image."
# Interface configuration
css = '''
.gradio-container {
max-width: 800px !important;
background: linear-gradient(135deg, #3e2f2f, #1e1712); /* Dark parchment colors */
color: #e4dccd; /* Cream text */
font-family: "Cinzel", serif; /* Medieval feel */
border-radius: 10px;
border: 3px solid #4b3028;
}
button {
background-color: #814d28; /* Rustic orange for buttons */
color: #fdf8f1;
font-weight: bold;
border-radius: 6px;
padding: 10px;
font-family: "Cinzel", serif;
font-size: 16px;
}
'''
iface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(
label="Enter Your Quest Description",
placeholder="Describe your D&D scene (e.g., 'A battle-worn knight in front of an ancient ruin').",
lines=2
),
outputs=gr.Image(
label="Generated Artwork",
type="auto"
),
title="🛡️ Dungeons & Dragons: Image Generator 🐉",
description="""
Forge your adventure into stunning visual art!
Describe your Dungeons & Dragons quest or scene, and the AI will create artwork inspired by your prompt.
Examples:
- "A fierce dragon soaring over a medieval castle at sunset."
- "A party of adventurers crossing a misty forest filled with glowing runes."
""",
examples=[
["A grand wizard casting spells in a crystal cave."],
["An armored paladin battling a horde of undead in a fiery battlefield."],
["An enchanted forest with glowing mushrooms and ancient trees."]
],
css=css
)
iface.launch()