Commit
·
bd30617
1
Parent(s):
fde96e8
css
Browse files
app.py
CHANGED
@@ -1,105 +1,154 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
import time
|
4 |
|
5 |
-
#
|
6 |
-
model = gr.load("models/prashanth970/flux-lora-uncensored")
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
custom_css = """
|
14 |
@import url('https://fonts.googleapis.com/css2?family=MedievalSharp&display=swap');
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
color: #f5f5f5;
|
19 |
-
font-family: 'MedievalSharp', cursive;
|
20 |
-
}
|
21 |
-
|
22 |
-
.gradio-container {
|
23 |
background-color: #2c2c2c;
|
24 |
border-radius: 15px;
|
25 |
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
|
26 |
padding: 20px;
|
|
|
27 |
}
|
28 |
|
29 |
-
.
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
font-size: 18px;
|
36 |
-
cursor: pointer;
|
37 |
-
transition: background-color 0.3s;
|
38 |
}
|
39 |
|
40 |
-
.
|
41 |
-
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
-
|
|
|
45 |
background-color: #3c3c3c;
|
46 |
-
color: #
|
47 |
border: 2px solid #8b4513;
|
48 |
border-radius: 8px;
|
49 |
padding: 12px;
|
50 |
font-size: 18px;
|
51 |
width: 100%;
|
52 |
box-sizing: border-box;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
|
59 |
-
.
|
|
|
|
|
|
|
|
|
|
|
60 |
border: 4px solid #8b4513;
|
61 |
border-radius: 15px;
|
62 |
margin-top: 20px;
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
-
|
|
|
|
|
66 |
color: #ffd700;
|
67 |
-
font-size:
|
68 |
-
font-weight: bold;
|
69 |
-
text-align: center;
|
70 |
-
margin-bottom: 20px;
|
71 |
-
}
|
72 |
-
|
73 |
-
.gr-description {
|
74 |
-
color: #ffd700;
|
75 |
-
font-size: 20px;
|
76 |
-
text-align: center;
|
77 |
-
margin-bottom: 20px;
|
78 |
}
|
79 |
|
80 |
-
|
|
|
81 |
color: #ffd700;
|
82 |
text-decoration: underline;
|
|
|
83 |
font-size: 18px;
|
|
|
84 |
}
|
85 |
|
86 |
-
.
|
87 |
color: #ffa500;
|
|
|
88 |
}
|
|
|
89 |
"""
|
90 |
|
91 |
-
#
|
92 |
iface = gr.Interface(
|
93 |
-
fn=
|
94 |
-
inputs=gr.Textbox(
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
title="🛡️ Dungeons & Dragons Image Generator ⚔️",
|
97 |
-
description="
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
css=custom_css,
|
101 |
-
|
|
|
102 |
)
|
103 |
|
104 |
-
# Launch the interface
|
105 |
-
iface.launch()
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
import time
|
4 |
|
5 |
+
# --- D&D Themed Image Generator ---
|
|
|
6 |
|
7 |
+
# Load the model (using Gradio's recommended method)
|
8 |
+
# Make sure the model ID is correct!
|
9 |
+
try:
|
10 |
+
model = gr.load("models/prashanth970/flux-lora-uncensored")
|
11 |
+
except Exception as e:
|
12 |
+
print(f"Error loading model: {e}")
|
13 |
+
model = None # Set model to None to prevent errors later
|
14 |
|
15 |
+
# Function to generate the image (with error handling)
|
16 |
+
def generate_image(prompt):
|
17 |
+
"""Generates an image based on the prompt, handling potential errors."""
|
18 |
+
if model is None:
|
19 |
+
return "Error: Model could not be loaded. Please check the model ID and your network connection."
|
20 |
+
|
21 |
+
try:
|
22 |
+
image = model(prompt)
|
23 |
+
return image
|
24 |
+
except Exception as e:
|
25 |
+
return f"An error occurred during image generation: {e}"
|
26 |
+
|
27 |
+
|
28 |
+
# Custom CSS for a D&D theme
|
29 |
custom_css = """
|
30 |
@import url('https://fonts.googleapis.com/css2?family=MedievalSharp&display=swap');
|
31 |
|
32 |
+
/* General Styles */
|
33 |
+
.dnd-container {
|
|
|
|
|
|
|
|
|
|
|
34 |
background-color: #2c2c2c;
|
35 |
border-radius: 15px;
|
36 |
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
|
37 |
padding: 20px;
|
38 |
+
font-family: 'MedievalSharp', cursive;
|
39 |
}
|
40 |
|
41 |
+
.dnd-title {
|
42 |
+
color: #ffd700;
|
43 |
+
font-size: 32px;
|
44 |
+
font-weight: bold;
|
45 |
+
text-align: center;
|
46 |
+
margin-bottom: 20px;
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
+
.dnd-description {
|
50 |
+
color: #ffd700;
|
51 |
+
font-size: 20px;
|
52 |
+
text-align: center;
|
53 |
+
margin-bottom: 20px;
|
54 |
}
|
55 |
|
56 |
+
/* Input Textbox */
|
57 |
+
.dnd-input textarea {
|
58 |
background-color: #3c3c3c;
|
59 |
+
color: #d1b579; /* Lighter text for better readability */
|
60 |
border: 2px solid #8b4513;
|
61 |
border-radius: 8px;
|
62 |
padding: 12px;
|
63 |
font-size: 18px;
|
64 |
width: 100%;
|
65 |
box-sizing: border-box;
|
66 |
+
font-family: 'MedievalSharp', cursive;
|
67 |
+
overflow-y: auto; /* Add scrollbar for long text */
|
68 |
+
resize: vertical; /* Allow vertical resizing */
|
69 |
+
}
|
70 |
+
|
71 |
+
.dnd-input textarea::placeholder {
|
72 |
+
color: #a39166; /* Slightly darker placeholder */
|
73 |
}
|
74 |
|
75 |
+
/* Generate Button */
|
76 |
+
.dnd-button button {
|
77 |
+
background-color: #8b4513;
|
78 |
+
color: #f5f5f5;
|
79 |
+
border: none;
|
80 |
+
border-radius: 8px;
|
81 |
+
padding: 12px 24px;
|
82 |
+
font-size: 18px;
|
83 |
+
cursor: pointer;
|
84 |
+
transition: background-color 0.3s;
|
85 |
+
width: 100%; /* Make button fill the container */
|
86 |
+
font-family: 'MedievalSharp', cursive;
|
87 |
}
|
88 |
|
89 |
+
.dnd-button button:hover {
|
90 |
+
background-color: #a0522d;
|
91 |
+
}
|
92 |
+
|
93 |
+
/* Output Image */
|
94 |
+
.dnd-output img {
|
95 |
border: 4px solid #8b4513;
|
96 |
border-radius: 15px;
|
97 |
margin-top: 20px;
|
98 |
+
display: block; /* Ensure image is treated as a block for centering */
|
99 |
+
margin-left: auto;
|
100 |
+
margin-right: auto;
|
101 |
}
|
102 |
|
103 |
+
/* Output Label */
|
104 |
+
.dnd-output div[data-testid='label'] {
|
105 |
+
text-align: center; /* Center the output label */
|
106 |
color: #ffd700;
|
107 |
+
font-size: 18px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
|
110 |
+
/* Links */
|
111 |
+
.dnd-link {
|
112 |
color: #ffd700;
|
113 |
text-decoration: underline;
|
114 |
+
font-family: 'MedievalSharp', cursive;
|
115 |
font-size: 18px;
|
116 |
+
|
117 |
}
|
118 |
|
119 |
+
.dnd-link:hover {
|
120 |
color: #ffa500;
|
121 |
+
font-family: 'MedievalSharp', cursive;
|
122 |
}
|
123 |
+
|
124 |
"""
|
125 |
|
126 |
+
# Gradio Interface
|
127 |
iface = gr.Interface(
|
128 |
+
fn=generate_image,
|
129 |
+
inputs=gr.Textbox(
|
130 |
+
lines=3,
|
131 |
+
label="📜 Enter Your Quest:",
|
132 |
+
placeholder="Describe your scene, hero, or epic landscape... Evoke the mists of Ravenloft, the sprawling city of Waterdeep, or the fiery depths of the Nine Hells!",
|
133 |
+
css=".dnd-input" # Apply custom CSS to the input
|
134 |
+
),
|
135 |
+
outputs=gr.Image(
|
136 |
+
type="pil",
|
137 |
+
label="🖼️ Your Legendary Vision",
|
138 |
+
css=".dnd-output" # Apply custom CSS to the output
|
139 |
+
),
|
140 |
title="🛡️ Dungeons & Dragons Image Generator ⚔️",
|
141 |
+
description="""
|
142 |
+
**Unleash Your Imagination!** Create heroes, maps, quests, and epic scenes to bring your campaigns to life.
|
143 |
+
Tailored for adventurers seeking inspiration or Dungeon Masters constructing their next grand story.
|
144 |
+
|
145 |
+
[Visit Our Website](https://chatdnd.net) | [Support Us](https://buymeacoffee.com/watchoutformike)
|
146 |
+
""",
|
147 |
css=custom_css,
|
148 |
+
theme=gr.themes.Soft(), #Added a soft theme to catch any styling
|
149 |
+
|
150 |
)
|
151 |
|
152 |
+
# Launch the interface
|
153 |
+
iface.launch()
|
154 |
+
|