Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,39 +43,42 @@ async def retry_query(payload, retries=5, delay=30):
|
|
43 |
@app.route('/', methods=['POST'])
|
44 |
async def generate_image():
|
45 |
try:
|
46 |
-
data = request.json
|
47 |
|
48 |
positive_prompt = data.get('positive_prompt', 'emma stone')
|
49 |
-
negative_prompt = data.get(
|
50 |
-
|
51 |
-
|
|
|
52 |
|
|
|
53 |
if style == "cinematic":
|
54 |
style = "cinematic shot, dynamic lighting, 75mm, Technicolor, Panavision, cinemascope, sharp focus, fine details, 8k, HDR, realism, realistic, key visual, film still, superb cinematic color grading, depth of field"
|
55 |
elif style == "realistic":
|
56 |
-
style = "realistic style, natural lighting, true-to-life details, high resolution, sharp focus, fine textures, authentic colors, accurate proportions, high dynamic range, clear and photorealistic"
|
57 |
elif style == "sci-fi":
|
58 |
style = "sci-fi style, futuristic technology, cyberpunk cityscape, neon lights, advanced robotics, alien landscapes, holographic interfaces, space exploration, dystopian themes, high-tech machinery"
|
59 |
elif style == "disney":
|
60 |
-
style = "3d, Disney character style, animated, cartoonish, whimsical, colorful, playful, charming, magical, fantastical, cute, endearing, family-friendly, storybook quality, iconic, expressive, vibrant colors, smooth lines, simple shapes, happy and adventurous"
|
61 |
else:
|
62 |
-
style = "fantasy style, magical landscapes, mythical creatures, enchanted forests, fairy tale elements, mystical realms, legendary beings, glowing effects, ethereal atmosphere, magical artifacts, ancient ruins"
|
63 |
-
|
64 |
-
seed = random.randint(0, 10000)
|
65 |
-
|
66 |
-
payload = {
|
67 |
-
"inputs": f"{positive_prompt}, {style}",
|
68 |
-
"negative_prompt": negative_prompt,
|
69 |
-
"options": {
|
70 |
-
"resolution": "4096×2160",
|
71 |
-
"quality": "high",
|
72 |
-
"seed": seed
|
73 |
-
}
|
74 |
-
}
|
75 |
|
76 |
image_urls = []
|
77 |
|
78 |
-
for image_count in range(3): # Generate 3 images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Retry mechanism with error handling
|
80 |
for attempt in range(3): # Try up to 3 times per image
|
81 |
image_bytes = await retry_query(payload)
|
|
|
43 |
@app.route('/', methods=['POST'])
|
44 |
async def generate_image():
|
45 |
try:
|
46 |
+
data = request.json
|
47 |
|
48 |
positive_prompt = data.get('positive_prompt', 'emma stone')
|
49 |
+
negative_prompt = data.get(
|
50 |
+
'negative_prompt', '[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, clothes, bad lighting, low-quality, deformed, text, poorly drawn, holding camera, bad art, bad angle, boring, low-resolution, worst quality, bad composition, disfigured'
|
51 |
+
)
|
52 |
+
style = data.get('style', '')
|
53 |
|
54 |
+
# Define style based on user input
|
55 |
if style == "cinematic":
|
56 |
style = "cinematic shot, dynamic lighting, 75mm, Technicolor, Panavision, cinemascope, sharp focus, fine details, 8k, HDR, realism, realistic, key visual, film still, superb cinematic color grading, depth of field"
|
57 |
elif style == "realistic":
|
58 |
+
style = "realistic style, natural lighting, true-to-life details, high resolution, sharp focus, fine textures, authentic colors, accurate proportions, high dynamic range, clear and photorealistic"
|
59 |
elif style == "sci-fi":
|
60 |
style = "sci-fi style, futuristic technology, cyberpunk cityscape, neon lights, advanced robotics, alien landscapes, holographic interfaces, space exploration, dystopian themes, high-tech machinery"
|
61 |
elif style == "disney":
|
62 |
+
style = "3d, Disney character style, animated, cartoonish, whimsical, colorful, playful, charming, magical, fantastical, cute, endearing, family-friendly, storybook quality, iconic, expressive, vibrant colors, smooth lines, simple shapes, happy and adventurous"
|
63 |
else:
|
64 |
+
style = "fantasy style, magical landscapes, mythical creatures, enchanted forests, fairy tale elements, mystical realms, legendary beings, glowing effects, ethereal atmosphere, magical artifacts, ancient ruins"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
image_urls = []
|
67 |
|
68 |
+
for image_count in range(3): # Generate 3 unique images
|
69 |
+
# Adjust the seed or input slightly for each image to ensure different results
|
70 |
+
seed = random.randint(0, 10000) + image_count # Slightly vary the seed
|
71 |
+
|
72 |
+
payload = {
|
73 |
+
"inputs": f"{positive_prompt}, {style}",
|
74 |
+
"negative_prompt": negative_prompt,
|
75 |
+
"options": {
|
76 |
+
"resolution": "4096×2160",
|
77 |
+
"quality": "high",
|
78 |
+
"seed": seed
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
# Retry mechanism with error handling
|
83 |
for attempt in range(3): # Try up to 3 times per image
|
84 |
image_bytes = await retry_query(payload)
|