File size: 2,350 Bytes
f14a738
 
 
 
 
b8dbbd0
f14a738
835cfeb
f14a738
835cfeb
f14a738
835cfeb
f14a738
 
 
 
 
 
 
 
835cfeb
 
f14a738
835cfeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f14a738
 
 
835cfeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f14a738
835cfeb
 
 
 
 
f14a738
 
835cfeb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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()