Skip to content

Commit b324f6c

Browse files
committed
Use OpenAI models
1 parent d3df79c commit b324f6c

2 files changed

Lines changed: 33 additions & 115 deletions

File tree

.github/scripts/gen-imgs.py

Lines changed: 28 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,10 @@ def gen_img(root, json_file):
3333
with open(os.path.join(root, json_file), 'r') as f:
3434
metadata = json.load(f)
3535

36-
output = get_painting_feature(metadata.get('displayName'), metadata.get('description'))
37-
feature = output.get('theme')
38-
imagery = output.get('imagery')
39-
colors = output.get('colors')
40-
41-
if isinstance(imagery, list):
42-
imagery = ", ".join(imagery)
43-
if isinstance(colors, list):
44-
colors = ", ".join(colors)
36+
prompt = get_painting_feature(metadata.get('displayName'), metadata.get('description'), metadata.get('homepage') or metadata.get('project'))
4537

4638
seed = random.randint(0, 2**32 - 1)
4739

48-
prompt = f"""
49-
Create an abstract oil painting that features or represents: {feature}.
50-
Use an expressive explosion of {colors} and hyper-detailed textures.
51-
Highlight the artwork with gleaming golden accents that radiate light amidst a brilliance of harmony.
52-
Incorporate ethereal elements like {imagery} to symbolize the peaceful blending of these forces.
53-
Ensure a perfect composition with intricate pearl filigree, capturing a serene and radiant ambiance.
54-
"""
55-
5640
prompt = re.sub(r'\s+', ' ', prompt).strip()
5741

5842
payload = {
@@ -88,125 +72,55 @@ def gen_img(root, json_file):
8872

8973
console.print(f"Done {out_file}", style="bold green")
9074

91-
def get_painting_feature(name, description):
92-
prompt = "I am making a painting about an open source package"
93-
if name:
94-
prompt += f" called “{name}”"
95-
if description:
96-
prompt += f" which is described as “{description}”"
97-
98-
prompt += f""".
99-
From that name and description extract some language that can be featured in the image.
100-
Eg. if the description is “foo is a bridge to bar” then output BRIDGE.
101-
Keep it physical. If the description is "foo is a dynamic runtime bridge to bar” then output BRIDGE, not DYNAMIC RUNTIME BRIDGE.
102-
Remember I need to paint this!
103-
If the name is a play on words then find the play on words. Eg “deno” is a play on dino ie. a dinosaur.
104-
If you know the logo for a project and the logo is a good theme, then say that. Eg. “deno”’s logo is a dinosaur.
105-
If the name contains a word I can paint, use it! Eg. from `libcap` you can say `cap`.
106-
Don’t be generic. I have ten million open source packages. eg. don’t pick `lib` or `code` or `syntax`, but eg. database is ok.
107-
I need the output as JSON "{{theme: ""}}.
108-
I am feeding the output to a script, so if you don’t output json in the above form my script will break.
109-
Thank you sir.
110-
"""
111-
prompt = re.sub(r'\s+', ' ', prompt).strip()
75+
def get_painting_feature(name, description, homepage):
76+
prompt = f"""
77+
I need an image prompt for an open source package so I can display it on https://pkgx.dev/pkgs/
11278
113-
print(prompt)
79+
The package is {name}: {description}
11480
115-
proc = subprocess.run(['pkgx', 'ollama', 'run', 'deepseek-r1', f"Instruct: {prompt}\nOutput: "], capture_output=True, text=True)
116-
result = proc.stdout
81+
The package homepage is {homepage} (feel free to go there and read it for more context).
11782
118-
console.print(result, style="yellow")
83+
An example prompt I have used is:
11984
120-
result = result[result.index("</think>") + len("</think>"):].strip()
85+
```
86+
Create an abstract oil painting that features: krampus
87+
Use an expressive explosion of Charcoal Gray, Off-White, Olive Green, Burnt Sienna, and Blush Pink with and hyper-detailed textures. Highlight the artwork with gleaming golden accents that radiate light amidst a brilliance of harmony.
88+
Incorporate ethereal elements like clouds, storms, rainbows, snow to symbolize the peaceful blending of these forces.
89+
Ensure a perfect composition with intricate pearl filigree, capturing a serene and radiant ambiance
90+
```
12191
122-
output = {}
92+
The package was krampus, a Command-line tool to kill one or more processes by port number.
93+
Extract a good object or theme to paint. Figure out colors and scenary. Maintain the fantastical oil-painting style.
12394
124-
match = re.search(r'{\s*"?theme"?:(.*?)}', result, re.DOTALL)
125-
if match:
126-
output['theme'] = match.group(1)
127-
else:
128-
# sometimes it just outputs the theme. Often with surrounding description, but whatever
129-
output['theme'] = re.sub(r'\s+', ' ', result).strip()
95+
Many packages are pretty abstract. If so, figure out some object to represent that the painting should feature.
96+
Don’t list the entire package description in the prompt as the image generator will not be able to handle it.
13097
131-
prompt = f"""
132-
I am making an abstract landscape oil painting with the theme "{output['theme']}".
133-
I need an appropriate color palette. Pick one of these:
98+
Avoid clock imagery unless the package is literally called “clock” or its purpose is time related.
99+
100+
End the prompt with `Ensure a perfect composition with intricate pearl filigree, capturing a serene and radiant ambiance` because it causes the image generator to stick to the style I want.
101+
102+
Pick complementary color palettes like:
134103
135-
```markdown
136104
- black, white, orange, beige, and pink
137105
- Charcoal Gray, Off-White, Olive Green, Burnt Sienna, and Blush Pink
138106
- Pearl White, Crimson Red, Champagne, and Pale Peach
139107
- Forest Green, Ivory, Coral Orange, Sand Beige, and Dusty Rose
140108
- Espresso Brown, Creamy White, Golden Yellow, Taupe, and Mauve
141109
- Jet Black, Soft Gray, Teal, Warm Amber, and Powder Pink
142-
```
143110
144-
If a theme requires it, adapt the color palette (ideally minimally), eg. if the theme is “Ruby” then add the color ruby!
145-
I need the output as JSON "{{colors: ""}}.
146-
Output the complete list item of colors, not just parts.
147-
I am feeding the output to a script, so if you don’t output json in the above form my script will break.
148-
Thank you sir.
149-
"""
150-
print(prompt)
111+
The above color palettes are just examples. You can pick any color palette you want (in the same vein).
151112
152-
prompt = f"Instruct: {prompt}\nOutput: "
153-
154-
proc = subprocess.run(['pkgx', 'ollama', 'run', 'deepseek-r1', prompt], capture_output=True, text=True)
155-
result = proc.stdout
156-
157-
console.print(result, style="blue")
158-
159-
result = result[result.index("</think>") + len("</think>"):].strip()
160-
161-
match = re.search(r'{\s*"?colors"?:(.*?)}', result, re.DOTALL)
162-
if match:
163-
output['colors'] = match.group(1)
164-
else:
165-
# sometimes it just outputs the theme. Often with surrounding description, but whatever
166-
output['colors'] = re.sub(r'\s+', ' ', result).strip()
167-
168-
prompt = f"""
169-
I have a theme: {output['theme']} and colors: {output['colors']}.
170-
Now pick from following list of imagery options to best fit that theme and color selection:
171-
172-
```markdown
173-
- oceans, waves, tides, coral reefs
174-
- volcanoes, lava, ash, craters
175-
- glaciers, icebergs, frost, polar lights
176-
- caves, stalactites, stalagmites, echoes
177-
- prairies, grasslands, sunrises
178-
- jungles, vines, canopies
179-
- cliffs, canyons, gorges, waterfalls
180-
- auroras, meteors, comets, cosmic dust, moons, planetscape
181-
- reefs, atolls, tropica
182-
- twilight, dawn, dusk, moonlight
183-
```
184-
185-
If none fit and you are inspired please provide your own imagery or adapt the options.
186-
I need the output as JSON "{{imagery: "FOO, BAR, BAZ, ETC"}}.
187-
Output the complete list item of imagery items, not just selected items.
188-
I am feeding the output to a script, so if you don’t output json in the above form my script will break.
189-
Thank you sir.
113+
Please only output the prompt as I am feeding this output directly to Stable Diffusion Web-UI.
190114
"""
191-
print(prompt)
192115

193-
prompt = f"Instruct: {prompt}\nOutput: "
116+
print(prompt)
194117

195-
proc = subprocess.run(['pkgx', 'ollama', 'run', 'deepseek-r1', prompt], capture_output=True, text=True)
118+
proc = subprocess.run(['pkgx', 'llm', 'prompt', f"Instruct: {prompt}\nOutput: "], capture_output=True, text=True)
196119
result = proc.stdout
197120

198-
console.print(result, style="green")
199-
200-
result = result[result.index("</think>") + len("</think>"):].strip()
201-
202-
match = re.search(r'{\s*"?imagery"?:(.*?)}', result, re.DOTALL)
203-
if match:
204-
output['imagery'] = match.group(1)
205-
else:
206-
# sometimes it just outputs the theme. Often with surrounding description, but whatever
207-
output['imagery'] = re.sub(r'\s+', ' ', result).strip()
121+
console.print(result, style="yellow")
208122

209-
return output
123+
return result
210124

211125
url = "http://127.0.0.1:7860/sdapi/v1/txt2img"
212126
console = Console()

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ on the CloudFront Distribution.
3737
### sync
3838

3939
```sh
40-
cd public/pkgs && AWS_PROFILE=tea \
40+
cd public/pkgs
41+
AWS_PROFILE=tea \
4142
aws s3 sync \
4243
. \
4344
s3://www.pkgx.dev/pkgs \
4445
--exclude=.DS_Store \
4546
--exclude=\*/.DS_Store \
4647
--exclude=.git/\*
48+
git add .
49+
git commit -m 'add pkgs'
50+
git push
4751
```

0 commit comments

Comments
 (0)