Spaces:
Running
Running
Commit
·
42a6543
1
Parent(s):
835cfeb
app.py
CHANGED
|
@@ -5,70 +5,35 @@ import io
|
|
| 5 |
import PIL
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
# API configuration
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
|
| 10 |
-
headers =
|
| 11 |
|
| 12 |
-
# Function to generate images
|
| 13 |
def generate_image(prompt):
|
| 14 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 15 |
|
| 16 |
if response.status_code == 200:
|
| 17 |
image_bytes = response.content
|
|
|
|
| 18 |
try:
|
| 19 |
image = Image.open(io.BytesIO(image_bytes))
|
| 20 |
return image
|
| 21 |
-
except PIL.UnidentifiedImageError:
|
| 22 |
-
return
|
| 23 |
else:
|
| 24 |
-
return
|
| 25 |
-
|
| 26 |
-
# Interface configuration
|
| 27 |
-
css = '''
|
| 28 |
-
.gradio-container {
|
| 29 |
-
max-width: 800px !important;
|
| 30 |
-
background: linear-gradient(135deg, #3e2f2f, #1e1712); /* Dark parchment colors */
|
| 31 |
-
color: #e4dccd; /* Cream text */
|
| 32 |
-
font-family: "Cinzel", serif; /* Medieval feel */
|
| 33 |
-
border-radius: 10px;
|
| 34 |
-
border: 3px solid #4b3028;
|
| 35 |
-
}
|
| 36 |
-
button {
|
| 37 |
-
background-color: #814d28; /* Rustic orange for buttons */
|
| 38 |
-
color: #fdf8f1;
|
| 39 |
-
font-weight: bold;
|
| 40 |
-
border-radius: 6px;
|
| 41 |
-
padding: 10px;
|
| 42 |
-
font-family: "Cinzel", serif;
|
| 43 |
-
font-size: 16px;
|
| 44 |
-
}
|
| 45 |
-
'''
|
| 46 |
|
| 47 |
iface = gr.Interface(
|
| 48 |
fn=generate_image,
|
| 49 |
-
inputs=
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
label="Generated Artwork",
|
| 56 |
-
type="auto"
|
| 57 |
-
),
|
| 58 |
-
title="🛡️ Dungeons & Dragons: Image Generator 🐉",
|
| 59 |
-
description="""
|
| 60 |
-
Forge your adventure into stunning visual art!
|
| 61 |
-
Describe your Dungeons & Dragons quest or scene, and the AI will create artwork inspired by your prompt.
|
| 62 |
-
Examples:
|
| 63 |
-
- "A fierce dragon soaring over a medieval castle at sunset."
|
| 64 |
-
- "A party of adventurers crossing a misty forest filled with glowing runes."
|
| 65 |
-
""",
|
| 66 |
examples=[
|
| 67 |
-
["A
|
| 68 |
-
["An
|
| 69 |
-
|
| 70 |
-
],
|
| 71 |
-
css=css
|
| 72 |
)
|
| 73 |
-
|
| 74 |
iface.launch()
|
|
|
|
|
|
| 5 |
import PIL
|
| 6 |
import os
|
| 7 |
|
|
|
|
| 8 |
API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
|
| 9 |
+
headers = os.getenv("SEECRET_TOKEN")
|
| 10 |
|
|
|
|
| 11 |
def generate_image(prompt):
|
| 12 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 13 |
|
| 14 |
if response.status_code == 200:
|
| 15 |
image_bytes = response.content
|
| 16 |
+
|
| 17 |
try:
|
| 18 |
image = Image.open(io.BytesIO(image_bytes))
|
| 19 |
return image
|
| 20 |
+
except PIL.UnidentifiedImageError as e:
|
| 21 |
+
return None
|
| 22 |
else:
|
| 23 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=generate_image,
|
| 27 |
+
inputs="text",
|
| 28 |
+
outputs="image",
|
| 29 |
+
title="🌄 Prompt to Image Generator 🌄",
|
| 30 |
+
description="Generate stunning images from your prompts using an AI model.",
|
| 31 |
+
layout="wide",
|
| 32 |
+
theme="huggingface",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
examples=[
|
| 34 |
+
["A surreal painting of a floating city at sunset"],
|
| 35 |
+
["An abstract landscape with vibrant colors and geometric shapes"]
|
| 36 |
+
]
|
|
|
|
|
|
|
| 37 |
)
|
|
|
|
| 38 |
iface.launch()
|
| 39 |
+
|