WatchOutForMike commited on
Commit
835cfeb
·
1 Parent(s): b8dbbd0
Files changed (2) hide show
  1. app.py +50 -15
  2. gradio_cached_examples/14/log.csv +3 -0
app.py CHANGED
@@ -5,35 +5,70 @@ import io
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
 
 
 
5
  import PIL
6
  import os
7
 
8
+ # API configuration
9
  API_URL = "https://api-inference.huggingface.co/models/Linaqruf/animagine-xl"
10
+ headers = {"Authorization": f"Bearer {os.getenv('SEECRET_TOKEN')}"}
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 "Failed to load the image. Ensure the prompt is appropriate."
23
  else:
24
+ return f"Error: {response.status_code}. Unable to generate the image."
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=gr.Textbox(
50
+ label="Enter Your Quest Description",
51
+ placeholder="Describe your D&D scene (e.g., 'A battle-worn knight in front of an ancient ruin').",
52
+ lines=2
53
+ ),
54
+ outputs=gr.Image(
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 grand wizard casting spells in a crystal cave."],
68
+ ["An armored paladin battling a horde of undead in a fiery battlefield."],
69
+ ["An enchanted forest with glowing mushrooms and ancient trees."]
70
+ ],
71
+ css=css
72
  )
 
73
 
74
+ iface.launch()
gradio_cached_examples/14/log.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ output,flag,username,timestamp
2
+ ,,,2025-01-19 23:20:59.642163
3
+ ,,,2025-01-19 23:21:00.668663