Spaces:
Running
Running
Commit
·
dcc4dc2
1
Parent(s):
3f1a8fc
Remove commented-out code for post body generation in create_post function
Browse files- image.py +75 -75
- post_blog.py +4 -4
image.py
CHANGED
@@ -24,81 +24,81 @@ def fix_base64_padding(data):
|
|
24 |
return data
|
25 |
|
26 |
def generate_image(title, category, summary):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
return None
|
103 |
|
104 |
def verify_image(image_data):
|
|
|
24 |
return data
|
25 |
|
26 |
def generate_image(title, category, summary):
|
27 |
+
print("Generating image...")
|
28 |
+
import time
|
29 |
+
start = time.time()
|
30 |
+
try:
|
31 |
+
try:
|
32 |
+
try:
|
33 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
34 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
35 |
+
client = Client()
|
36 |
+
img_data = client.images.generate(
|
37 |
+
provider=RetryProvider(
|
38 |
+
providers=[ReplicateHome, Airforce],
|
39 |
+
shuffle=True,
|
40 |
+
single_provider_retry=True,
|
41 |
+
max_retries=3,
|
42 |
+
),
|
43 |
+
model="sdxl",
|
44 |
+
prompt=prompt,
|
45 |
+
negative_prompt=negative,
|
46 |
+
response_format="b64_json",
|
47 |
+
width=1024,
|
48 |
+
height=576,
|
49 |
+
).data[0].b64_json
|
50 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
51 |
+
if img_data:
|
52 |
+
return f"data:image/png;base64,{img_data}"
|
53 |
+
return None
|
54 |
+
except Exception as e:
|
55 |
+
print(f"Error generating image: {e}")
|
56 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
57 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
58 |
+
client = Client()
|
59 |
+
img_data = client.images.generate(
|
60 |
+
provider=RetryProvider(
|
61 |
+
providers=[Airforce, PollinationsAI, BlackboxCreateAgent],
|
62 |
+
shuffle=True,
|
63 |
+
single_provider_retry=True,
|
64 |
+
max_retries=3,
|
65 |
+
),
|
66 |
+
model="flux",
|
67 |
+
prompt=prompt,
|
68 |
+
negative_prompt=negative,
|
69 |
+
response_format="b64_json",
|
70 |
+
width=1024,
|
71 |
+
height=576,
|
72 |
+
).data[0].b64_json
|
73 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
74 |
+
if img_data:
|
75 |
+
return f"data:image/png;base64,{img_data}"
|
76 |
+
return None
|
77 |
+
except Exception as e:
|
78 |
+
print(f"Error generating image: {e}")
|
79 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
80 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
81 |
+
client = Client()
|
82 |
+
img_data = client.images.generate(
|
83 |
+
provider=RetryProvider(
|
84 |
+
providers=[BlackForestLabsFlux1Schnell, VoodoohopFlux1Schnell],
|
85 |
+
shuffle=True,
|
86 |
+
single_provider_retry=True,
|
87 |
+
max_retries=3,
|
88 |
+
),
|
89 |
+
model="flux-schnell",
|
90 |
+
prompt=prompt,
|
91 |
+
negative_prompt=negative,
|
92 |
+
response_format="b64_json",
|
93 |
+
width=1024,
|
94 |
+
height=576,
|
95 |
+
).data[0].b64_json
|
96 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
97 |
+
if img_data:
|
98 |
+
return f"data:image/png;base64,{img_data}"
|
99 |
+
return None
|
100 |
+
except Exception as e:
|
101 |
+
print(f"Error generating image: {e}")
|
102 |
return None
|
103 |
|
104 |
def verify_image(image_data):
|
post_blog.py
CHANGED
@@ -115,10 +115,10 @@ def create_post(doi, title, category, summary, mindmap, citation):
|
|
115 |
post_category = f"{category}"
|
116 |
try:
|
117 |
post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
|
118 |
-
print("_____________________\n\n",title,"\n\n_____________________")
|
119 |
-
with open(f'{title.replace(" ", "_")}.html', 'w', encoding='utf-8') as f:
|
120 |
-
|
121 |
-
exit()
|
122 |
except Exception as e:
|
123 |
print(f"Error generating post: {e}")
|
124 |
return None, None, None, None
|
|
|
115 |
post_category = f"{category}"
|
116 |
try:
|
117 |
post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
|
118 |
+
# print("_____________________\n\n",title,"\n\n_____________________")
|
119 |
+
# with open(f'{title.replace(" ", "_")}.html', 'w', encoding='utf-8') as f:
|
120 |
+
# f.write(post_body)
|
121 |
+
# exit()
|
122 |
except Exception as e:
|
123 |
print(f"Error generating post: {e}")
|
124 |
return None, None, None, None
|