WatchOutForMike commited on
Commit
90c4804
·
1 Parent(s): bd30617
Files changed (1) hide show
  1. app.py +94 -100
app.py CHANGED
@@ -2,153 +2,147 @@ 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
-
 
2
  from PIL import Image
3
  import time
4
 
5
+ # Load the model from Hugging Face
6
+ model = gr.load("models/prashanth970/flux-lora-uncensored")
7
+
8
+ # Define Gradio interface with a loading animation
9
+ def model_with_loading(prompt):
10
+ # Simulate a loading animation for immersion
11
+ print("✨ Summoning the arcane energies to manifest your vision... ✨")
12
+ time.sleep(2) # Simulate processing time
13
+ result = model(prompt)
14
+ return result
15
+
16
+ # Custom CSS for D&D theme
 
 
 
 
 
 
 
 
 
 
 
 
17
  custom_css = """
18
  @import url('https://fonts.googleapis.com/css2?family=MedievalSharp&display=swap');
19
 
20
+ /* Global Styles */
21
+ body {
22
+ background: url('https://i.imgur.com/1Q3xL9m.jpg') no-repeat center center fixed; /* Faux parchment texture */
23
+ background-size: cover;
24
+ color: #f5f5f5;
 
25
  font-family: 'MedievalSharp', cursive;
26
+ margin: 0;
27
+ padding: 0;
28
  }
29
 
30
+ .gradio-container {
31
+ background-color: rgba(0, 0, 0, 0.8);
32
+ border-radius: 15px;
33
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
34
+ padding: 20px;
35
+ max-width: 800px;
36
+ margin: 0 auto;
37
+ margin-top: 50px;
38
+ border: 4px solid #8b4513;
 
 
 
 
39
  }
40
 
41
+ /* Buttons */
42
+ .gr-button {
43
+ background-color: #8b4513;
44
+ color: #f5f5f5;
45
+ border: none;
46
  border-radius: 8px;
47
+ padding: 12px 24px;
48
  font-size: 18px;
49
+ cursor: pointer;
50
+ transition: background-color 0.3s, transform 0.3s;
51
  font-family: 'MedievalSharp', cursive;
 
 
52
  }
53
 
54
+ .gr-button:hover {
55
+ background-color: #a0522d;
56
+ transform: scale(1.05);
57
  }
58
 
59
+ /* Textbox */
60
+ .gr-textbox {
61
+ background-color: #3c3c3c;
62
  color: #f5f5f5;
63
+ border: 2px solid #8b4513;
64
  border-radius: 8px;
65
+ padding: 12px;
66
  font-size: 18px;
67
+ width: 100%;
68
+ box-sizing: border-box;
 
69
  font-family: 'MedievalSharp', cursive;
70
  }
71
 
72
+ .gr-textbox::placeholder {
73
+ color: #d3d3d3;
74
  }
75
 
76
+ /* Image Outputs */
77
+ .gr-image {
78
  border: 4px solid #8b4513;
79
  border-radius: 15px;
80
  margin-top: 20px;
81
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
 
 
82
  }
83
 
84
+ /* Titles and Headings */
85
+ .gr-title {
 
86
  color: #ffd700;
87
+ font-size: 36px;
88
+ font-weight: bold;
89
+ text-align: center;
90
+ margin-bottom: 20px;
91
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
92
+ }
93
+
94
+ .gr-description {
95
+ color: #ffd700;
96
+ font-size: 20px;
97
+ text-align: center;
98
+ margin-bottom: 20px;
99
+ font-family: 'MedievalSharp', cursive;
100
  }
101
 
102
  /* Links */
103
+ .gr-link {
104
  color: #ffd700;
105
  text-decoration: underline;
 
106
  font-size: 18px;
107
+ font-family: 'MedievalSharp', cursive;
108
  }
109
 
110
+ .gr-link:hover {
111
  color: #ffa500;
 
112
  }
113
 
114
+ /* Loading Animation */
115
+ .loading-message {
116
+ color: #ffd700;
117
+ font-size: 18px;
118
+ text-align: center;
119
+ margin-top: 20px;
120
+ font-family: 'MedievalSharp', cursive;
121
+ animation: flicker 1.5s infinite alternate;
122
+ }
123
+
124
+ @keyframes flicker {
125
+ 0% { opacity: 1; }
126
+ 100% { opacity: 0.8; }
127
+ }
128
  """
129
 
130
+ # Define Gradio interface
131
  iface = gr.Interface(
132
+ fn=model_with_loading,
133
  inputs=gr.Textbox(
134
+ lines=5,
135
+ label="📜 Describe Your Adventure:",
136
+ placeholder="E.g., 'A dragon perched upon a mountain of gold, surrounded by mist and fire.'",
 
 
 
 
 
 
137
  ),
138
+ outputs=gr.Image(type="pil", label="✨ The Arcane Vision Appears "),
139
+ title="⚔️ Dungeons & Dragons Artificer ⚔️",
140
+ description="**Conjure Your Imagination Into Reality!** Summon legendary heroes, create epic landscapes, or design fantastical creatures for your campaigns. Perfect for adventurers and Dungeon Masters alike. <br>"
141
+ "[Explore Our Lore](https://chatdnd.net) | [Support the Guild](https://buymeacoffee.com/watchoutformike)",
 
 
 
142
  css=custom_css,
143
+ live=False,
144
+ allow_flagging="never" # Disable flagging for simpler use
145
  )
146
 
147
  # Launch the interface
148
  iface.launch()