arpit13 commited on
Commit
6a21df7
ยท
verified ยท
1 Parent(s): 977b325

Create setup.py

Browse files
Files changed (1) hide show
  1. setup.py +420 -0
setup.py ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Image Creator: Enhanced UI and UX
2
+ # Part 1: Core Setup, Model Classes and API Configuration
3
+
4
+ import gradio as gr
5
+ import logging
6
+ import sys
7
+ import random
8
+ import time
9
+ from huggingface_hub import InferenceClient
10
+ from PIL import Image
11
+ import io
12
+ import base64
13
+
14
+ os.getenv("HF_API_KEY")
15
+
16
+ # Set up logging
17
+ logging.basicConfig(
18
+ level=logging.INFO,
19
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
20
+ handlers=[logging.StreamHandler(sys.stdout)]
21
+ )
22
+ logger = logging.getLogger("ai_image_creator")
23
+
24
+ # =============== MODEL CLIENTS SETUP ===============
25
+ def setup_client(api_key, provider=None):
26
+ """Initialize and return API client"""
27
+ try:
28
+ if provider:
29
+ client = InferenceClient(provider=provider, api_key=api_key)
30
+ logger.info(f"{provider} client initialized successfully")
31
+ else:
32
+ client = InferenceClient(api_key=api_key)
33
+ logger.info("Hugging Face client initialized successfully")
34
+ return client
35
+ except Exception as e:
36
+ logger.error(f"Error initializing client: {str(e)}")
37
+ return None
38
+
39
+ # Initialize clients
40
+ try:
41
+ # Replace with your actual HF API key
42
+ hf_api_key = os.getenv("HF_API_KEY")
43
+ hf_client = setup_client(hf_api_key)
44
+ logger.info("Hugging Face client created successfully")
45
+
46
+ # Set up Llama client if API key is provided
47
+ llama_api_key = os.getenv("HF_API_KEY") # Replace with actual key if available
48
+ try:
49
+ llama_client = setup_client(llama_api_key, "sambanova")
50
+ use_llama = True
51
+ logger.info("Llama client created successfully")
52
+ except Exception as e:
53
+ logger.warning(f"Llama client not available: {str(e)}. Will use fallback enhancement.")
54
+ llama_client = None
55
+ use_llama = False
56
+ except Exception as e:
57
+ logger.error(f"Failed to create Hugging Face client: {str(e)}")
58
+ hf_client = None
59
+ llama_client = None
60
+ use_llama = False
61
+
62
+ # =============== DATA MODELS ===============
63
+
64
+ # Image Models with friendly names, descriptions and icons
65
+ IMAGE_MODELS = {
66
+ "stabilityai/stable-diffusion-xl-base-1.0": {
67
+ "display_name": "SDXL 1.0",
68
+ "description": "Best overall quality, slower generation",
69
+ "icon": "โญ",
70
+ "speed": "slow",
71
+ "quality": "excellent"
72
+ },
73
+ "runwayml/stable-diffusion-v1-5": {
74
+ "display_name": "SD 1.5",
75
+ "description": "Good for general purpose, faster generation",
76
+ "icon": "๐Ÿš€",
77
+ "speed": "fast",
78
+ "quality": "good"
79
+ },
80
+ "stabilityai/stable-diffusion-2-1": {
81
+ "display_name": "SD 2.1",
82
+ "description": "Improved details, balanced speed and quality",
83
+ "icon": "โœจ",
84
+ "speed": "medium",
85
+ "quality": "very good"
86
+ },
87
+ "prompthero/openjourney": {
88
+ "display_name": "OpenJourney",
89
+ "description": "Midjourney-like stylized results",
90
+ "icon": "๐ŸŽจ",
91
+ "speed": "medium",
92
+ "quality": "stylized"
93
+ },
94
+ "dreamlike-art/dreamlike-diffusion-1.0": {
95
+ "display_name": "Dreamlike",
96
+ "description": "Artistic style with dreamy aesthetics",
97
+ "icon": "๐Ÿ’ซ",
98
+ "speed": "medium",
99
+ "quality": "artistic"
100
+ }
101
+ }
102
+
103
+ # Creation types with icons and detailed descriptions
104
+ CREATION_TYPES = {
105
+ "Realistic Photo": {
106
+ "description": "Create a photorealistic image with natural details and lighting",
107
+ "icon": "๐Ÿ“ท",
108
+ "prompt_hint": "Try to include details about lighting, time of day, and environment"
109
+ },
110
+ "Digital Art": {
111
+ "description": "Create colorful digital artwork with clean lines and vibrant colors",
112
+ "icon": "๐Ÿ–Œ๏ธ",
113
+ "prompt_hint": "Consider specifying color palette and mood for better results"
114
+ },
115
+ "Fantasy Illustration": {
116
+ "description": "Create magical and fantastical scenes with otherworldly elements",
117
+ "icon": "๐Ÿง™",
118
+ "prompt_hint": "Describe magical elements, creatures, and environments in detail"
119
+ },
120
+ "Concept Art": {
121
+ "description": "Create professional concept art for characters, environments or objects",
122
+ "icon": "๐ŸŽฎ",
123
+ "prompt_hint": "Include details about perspective, purpose, and design influences"
124
+ },
125
+ "Anime/Manga": {
126
+ "description": "Create Japanese anime or manga style illustration",
127
+ "icon": "๐Ÿ™",
128
+ "prompt_hint": "Specify anime aesthetics like shading style and character features"
129
+ },
130
+ "Oil Painting": {
131
+ "description": "Create an image with oil painting textures and artistic brushstrokes",
132
+ "icon": "๐Ÿ–ผ๏ธ",
133
+ "prompt_hint": "Consider describing texture, brushwork style, and canvas feel"
134
+ },
135
+ "Watercolor": {
136
+ "description": "Create a soft watercolor illustration with subtle color blending",
137
+ "icon": "๐Ÿ’ง",
138
+ "prompt_hint": "Mention color blending, paper texture, and watercolor-specific effects"
139
+ },
140
+ "Sketch": {
141
+ "description": "Create a detailed sketch or drawing with line art focus",
142
+ "icon": "โœ๏ธ",
143
+ "prompt_hint": "Describe line weight, hatching style, and sketch medium (pencil, charcoal, etc.)"
144
+ },
145
+ "3D Rendering": {
146
+ "description": "Create an image that looks like a 3D rendered scene with realistic lighting",
147
+ "icon": "๐Ÿ’ป",
148
+ "prompt_hint": "Include details about lighting setup, materials, and camera perspective"
149
+ },
150
+ "Pixel Art": {
151
+ "description": "Create retro-style pixel art with limited color palette",
152
+ "icon": "๐Ÿ‘พ",
153
+ "prompt_hint": "Specify resolution, color limitations, and pixel art style (e.g., 16-bit, 8-bit)"
154
+ }
155
+ }
156
+
157
+ # Art styles with icons and detailed descriptions
158
+ ART_STYLES = {
159
+ "Photorealistic": {
160
+ "description": "Detailed realistic style that resembles a photograph with accurate lighting and textures",
161
+ "icon": "๐Ÿ“ธ",
162
+ "examples": "Works by Chuck Close, Richard Estes, or modern 3D renderings"
163
+ },
164
+ "Impressionist": {
165
+ "description": "Soft brushstrokes that capture light and atmosphere over precise details, like Monet",
166
+ "icon": "๐ŸŒˆ",
167
+ "examples": "Claude Monet, Pierre-Auguste Renoir, Camille Pissarro"
168
+ },
169
+ "Surrealist": {
170
+ "description": "Dreamlike quality with impossible or irrational scenes, like Salvador Dali",
171
+ "icon": "๐ŸŒ€",
172
+ "examples": "Salvador Dali, Renรฉ Magritte, Frida Kahlo"
173
+ },
174
+ "Pop Art": {
175
+ "description": "Bold colors, sharp lines and popular culture references, like Andy Warhol",
176
+ "icon": "๐ŸŽญ",
177
+ "examples": "Andy Warhol, Roy Lichtenstein, Keith Haring"
178
+ },
179
+ "Minimalist": {
180
+ "description": "Simplified forms, limited color palette, and clean composition with minimal elements",
181
+ "icon": "โฌœ",
182
+ "examples": "Piet Mondrian, Kazimir Malevich, Agnes Martin"
183
+ },
184
+ "Abstract": {
185
+ "description": "Non-representational style using shapes, colors, and forms to express ideas",
186
+ "icon": "๐Ÿ”ถ",
187
+ "examples": "Wassily Kandinsky, Jackson Pollock, Mark Rothko"
188
+ },
189
+ "Cubist": {
190
+ "description": "Geometric shapes and multiple perspectives shown simultaneously, like Picasso",
191
+ "icon": "๐Ÿ“",
192
+ "examples": "Pablo Picasso, Georges Braque, Juan Gris"
193
+ },
194
+ "Art Nouveau": {
195
+ "description": "Ornate, flowing lines inspired by natural forms with decorative elegance",
196
+ "icon": "๐ŸŒฟ",
197
+ "examples": "Alphonse Mucha, Gustav Klimt, Antoni Gaudรญ"
198
+ },
199
+ "Gothic": {
200
+ "description": "Dark, medieval-inspired aesthetic with dramatic lighting and architectural elements",
201
+ "icon": "๐Ÿฐ",
202
+ "examples": "Zdzisล‚aw Beksiล„ski, H.R. Giger, medieval architecture"
203
+ },
204
+ "Cyberpunk": {
205
+ "description": "Futuristic dystopian style with neon colors, technology, and urban decay",
206
+ "icon": "๐Ÿค–",
207
+ "examples": "Blade Runner, Ghost in the Shell, Akira"
208
+ },
209
+ "Steampunk": {
210
+ "description": "Victorian-era aesthetic combined with steam-powered technology and brass elements",
211
+ "icon": "โš™๏ธ",
212
+ "examples": "Works by James Ng, Keith Thompson, retrofuturistic Jules Verne adaptations"
213
+ },
214
+ "Retro/Vintage": {
215
+ "description": "Nostalgic style reminiscent of past decades with period-appropriate elements",
216
+ "icon": "๐Ÿ“บ",
217
+ "examples": "1950s advertisements, vintage travel posters, pulp magazine covers"
218
+ },
219
+ "Art Deco": {
220
+ "description": "Geometric patterns, bold colors, and luxurious materials in a symmetrical style",
221
+ "icon": "๐Ÿข",
222
+ "examples": "Works from the 1920s-30s, Chrysler Building, Tamara de Lempicka paintings"
223
+ },
224
+ "Baroque": {
225
+ "description": "Dramatic, ornate style with rich details, contrast, and dynamic composition",
226
+ "icon": "๐Ÿ‘‘",
227
+ "examples": "Caravaggio, Rembrandt, Peter Paul Rubens"
228
+ },
229
+ "Ukiyo-e": {
230
+ "description": "Traditional Japanese woodblock print style with flat areas of color and strong outlines",
231
+ "icon": "๐ŸŒŠ",
232
+ "examples": "Hokusai's Great Wave, Hiroshige's landscapes, traditional Japanese prints"
233
+ },
234
+ "Comic Book": {
235
+ "description": "Bold outlines, bright colors, and action-oriented composition like classic comics",
236
+ "icon": "๐Ÿ’ฅ",
237
+ "examples": "Jack Kirby, Steve Ditko, modern Marvel/DC art styles"
238
+ },
239
+ "Psychedelic": {
240
+ "description": "Vibrant, swirling colors with abstract patterns inspired by 1960s art",
241
+ "icon": "๐ŸŒˆ",
242
+ "examples": "1960s concert posters, Peter Max, Alex Grey"
243
+ },
244
+ "Vaporwave": {
245
+ "description": "Glitch aesthetics with pastel colors, 80s/90s nostalgia and digital elements",
246
+ "icon": "๐Ÿ“ผ",
247
+ "examples": "Retrowave aesthetics, 80s digital graphics, glitch art"
248
+ },
249
+ "Studio Ghibli": {
250
+ "description": "Whimsical, detailed animation style inspired by Japanese animated films",
251
+ "icon": "๐Ÿ‰",
252
+ "examples": "Spirited Away, My Neighbor Totoro, Howl's Moving Castle"
253
+ },
254
+ "Hyperrealism": {
255
+ "description": "Extremely detailed realism that exceeds photograph-like precision",
256
+ "icon": "๐Ÿ”",
257
+ "examples": "Works by Roberto Bernardi, Denis Peterson, Gottfried Helnwein"
258
+ }
259
+ }
260
+
261
+ # Moods with icons and descriptions
262
+ MOODS = {
263
+ "Happy": {
264
+ "description": "Bright, cheerful atmosphere with warm colors",
265
+ "icon": "๐Ÿ˜Š",
266
+ "color_palette": "Warm and vibrant colors: yellows, bright oranges, light blues"
267
+ },
268
+ "Sad": {
269
+ "description": "Melancholic atmosphere with muted colors",
270
+ "icon": "๐Ÿ˜ข",
271
+ "color_palette": "Muted blues, grays, desaturated colors, cool tones"
272
+ },
273
+ "Mysterious": {
274
+ "description": "Enigmatic atmosphere with shadows and hidden elements",
275
+ "icon": "๐Ÿ”ฎ",
276
+ "color_palette": "Deep purples, dark blues, hints of teal, selective lighting"
277
+ },
278
+ "Peaceful": {
279
+ "description": "Serene, calm atmosphere with gentle lighting",
280
+ "icon": "๐Ÿ•Š๏ธ",
281
+ "color_palette": "Soft blues, gentle greens, pastel colors, balanced light"
282
+ },
283
+ "Tense": {
284
+ "description": "Suspenseful atmosphere with dramatic lighting",
285
+ "icon": "๐Ÿ˜ฐ",
286
+ "color_palette": "High contrast, dark shadows, selective reds, strong highlights"
287
+ },
288
+ "Whimsical": {
289
+ "description": "Playful, imaginative atmosphere with fanciful elements",
290
+ "icon": "๐Ÿฆ„",
291
+ "color_palette": "Pastels, candy colors, unexpected color combinations"
292
+ },
293
+ "Dark": {
294
+ "description": "Gloomy atmosphere with deep shadows and low lighting",
295
+ "icon": "๐ŸŒ‘",
296
+ "color_palette": "Dark blues, blacks, deep greens, minimal highlights"
297
+ },
298
+ "Energetic": {
299
+ "description": "Dynamic, vibrant atmosphere with strong colors and movement",
300
+ "icon": "โšก",
301
+ "color_palette": "Saturated primary colors, bold contrasts, vibrant hues"
302
+ },
303
+ "Romantic": {
304
+ "description": "Soft, dreamy atmosphere with warm, gentle lighting",
305
+ "icon": "โค๏ธ",
306
+ "color_palette": "Soft pinks, gentle reds, golden highlights, warm tones"
307
+ },
308
+ "Epic": {
309
+ "description": "Grand, impressive atmosphere with dramatic scale and lighting",
310
+ "icon": "๐Ÿ”๏ธ",
311
+ "color_palette": "Bold colors, dramatic contrast, atmospheric lighting, expansive scale"
312
+ }
313
+ }
314
+
315
+ # Example prompts with rich metadata
316
+ EXAMPLE_PROMPTS = [
317
+ {
318
+ "text": "A serene lake at sunset with mountains in the background and a small wooden boat floating nearby",
319
+ "thumbnail_desc": "Peaceful lake scene at sunset",
320
+ "creation_type": "Realistic Photo",
321
+ "art_style": "Photorealistic",
322
+ "mood": "Peaceful",
323
+ "tags": ["nature", "landscape", "water", "sunset"]
324
+ },
325
+ {
326
+ "text": "A futuristic cityscape with flying cars, neon lights, and tall skyscrapers under a night sky with two moons",
327
+ "thumbnail_desc": "Futuristic city with flying cars",
328
+ "creation_type": "Concept Art",
329
+ "art_style": "Cyberpunk",
330
+ "mood": "Mysterious",
331
+ "tags": ["scifi", "future", "urban", "night"]
332
+ },
333
+ {
334
+ "text": "A close-up portrait of an elderly craftsman with weathered hands working on an intricate wooden carving in his workshop",
335
+ "thumbnail_desc": "Elderly craftsman working with wood",
336
+ "creation_type": "Oil Painting",
337
+ "art_style": "Hyperrealism",
338
+ "mood": "Peaceful",
339
+ "tags": ["portrait", "craftsmanship", "elderly", "detail"]
340
+ },
341
+ {
342
+ "text": "A magical forest with glowing mushrooms, fairy lights, and a small cottage with smoke coming from the chimney",
343
+ "thumbnail_desc": "Magical forest with glowing elements",
344
+ "creation_type": "Fantasy Illustration",
345
+ "art_style": "Studio Ghibli",
346
+ "mood": "Whimsical",
347
+ "tags": ["fantasy", "forest", "magic", "cottage"]
348
+ },
349
+ {
350
+ "text": "A cybernetic samurai with glowing blue circuits standing in a rainy Tokyo street at night",
351
+ "thumbnail_desc": "Cybernetic samurai in rainy Tokyo",
352
+ "creation_type": "Digital Art",
353
+ "art_style": "Cyberpunk",
354
+ "mood": "Dark",
355
+ "tags": ["character", "cyberpunk", "samurai", "rain"]
356
+ },
357
+ {
358
+ "text": "A cute cat with dragon wings and tiny horns sleeping on a pile of gold coins",
359
+ "thumbnail_desc": "Cat with dragon features on gold",
360
+ "creation_type": "Fantasy Illustration",
361
+ "art_style": "Comic Book",
362
+ "mood": "Whimsical",
363
+ "tags": ["creature", "fantasy", "cute", "treasure"]
364
+ },
365
+ {
366
+ "text": "An ancient temple covered in vines and moss, partially sunken into a crystal-clear cenote in the jungle",
367
+ "thumbnail_desc": "Ancient temple in jungle cenote",
368
+ "creation_type": "Concept Art",
369
+ "art_style": "Photorealistic",
370
+ "mood": "Mysterious",
371
+ "tags": ["architecture", "ruins", "jungle", "water"]
372
+ },
373
+ {
374
+ "text": "A cozy coffee shop interior with rain falling outside the windows, soft lighting, and a few people reading books",
375
+ "thumbnail_desc": "Cozy rainy day in coffee shop",
376
+ "creation_type": "Digital Art",
377
+ "art_style": "Impressionist",
378
+ "mood": "Peaceful",
379
+ "tags": ["interior", "rainy", "cozy", "urban"]
380
+ }
381
+ ]
382
+
383
+ # CSS for enhanced UI styling - Will be included in part 2
384
+
385
+ # =============== HELPER FUNCTIONS ===============
386
+
387
+ # Helper function to format dropdown choices with icons
388
+ def format_dropdown_choices(options_dict):
389
+ return [f"{info.get('icon', 'โ€ข')} {key}" for key in options_dict.keys()]
390
+
391
+ # Helper function to extract the key from formatted choice
392
+ def extract_key(formatted_choice):
393
+ # Skip the icon and space at the beginning
394
+ parts = formatted_choice.split(' ', 1)
395
+ if len(parts) > 1:
396
+ return parts[1]
397
+ return formatted_choice
398
+
399
+ # Function to load example prompt
400
+ def load_example(example_index):
401
+ if example_index < 0 or example_index >= len(EXAMPLE_PROMPTS):
402
+ return "", "", "", ""
403
+
404
+ example = EXAMPLE_PROMPTS[example_index]
405
+ creation = f"{CREATION_TYPES[example['creation_type']]['icon']} {example['creation_type']}"
406
+ art = f"{ART_STYLES[example['art_style']]['icon']} {example['art_style']}"
407
+ mood = f"{MOODS[example['mood']]['icon']} {example['mood']}"
408
+
409
+ return example["text"], creation, art, mood
410
+
411
+ # Get model key from formatted display name
412
+ def get_model_key(formatted_name):
413
+ # Extract display name without the icon
414
+ if ' ' in formatted_name:
415
+ display_name = formatted_name.split(' ', 1)[1]
416
+ # Find the corresponding key
417
+ for key, info in IMAGE_MODELS.items():
418
+ if info['display_name'] == display_name:
419
+ return key
420
+ return list(IMAGE_MODELS.keys())[0] # Default to first model if not found