Skip to content

Commit

Permalink
feat: auto generate images
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Jun 22, 2023
1 parent ac4f1d6 commit 46d41b2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you would like to make a donation to support development, please use [GitHub
## Features

- Create unique AI-generated artwork from spoken conversations
- Manual or voice-activated summary generation for on-demand art
- Automatic, manual or voice-activated summary generation for on-demand art
- User-friendly UI, optimized for both desktop and mobile
- Real-time updates and remote control via WebSockets
- Integrated config editor for customization
Expand Down Expand Up @@ -181,6 +181,21 @@ image:
order: recent
```

### `autogen`

Images can be automatically generated by creating random summaries. This can be scheduled with a cron expression. Keywords can be passed to help guide the summary.

```yaml
# autogen settings (default: shown below)
autogen:
# schedule as a cron expression for processing transcripts (at every 15th and 45th minute)
cron: '15,45 * * * *'
prompt: Provide a random short description to describe a picture. It should be no more than one or two sentences. If keywords are provided select a couple at random to help guide the description.
# keywords to guide the summary
keywords: []
```

### `transcript`

Images are generated by processing transcripts. This can be scheduled with a cron expression. All of the transcripts within X minutes will then be processed by OpenAI using `openai.summary.prompt` to summarize the transcripts.
Expand Down
1 change: 1 addition & 0 deletions api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const start = async () => {
emitter.setup();
socket.connect(server);
cron.transcript();
cron.autogen();
cron.heartbeat();
});
};
Expand Down
6 changes: 6 additions & 0 deletions api/src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export default {
telemetry: true,
logs: { level: 'verbose' },
time: { timezone: 'UTC', format: null },
autogen: {
cron: '15,45 * * * *',
prompt:
'Provide a random short description to describe a picture. It should be no more than one or two sentences. If keywords are provided select a couple at random to help guide the description.',
keywords: [],
},
image: {
interval: 60,
order: 'recent',
Expand Down
6 changes: 6 additions & 0 deletions api/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const schema = z.object({
}),
image: z.union([
z.object({
autogen: z.object({
enable: z.boolean(),
cron: z.string(),
prompt: z.string(),
keywords: z.array(z.string()),
}),
size: z.enum(['1024x1024', '512x512', '256x256']),
style: z.array(z.string()).min(1),
}),
Expand Down
20 changes: 20 additions & 0 deletions api/src/util/cron.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { version } = require('../../package.json');
const {
TELEMETRY,
TRANSCRIPT: { CRON, MINUTES, MINIMUM },
AUTOGEN,
} = config();

export default {
Expand Down Expand Up @@ -94,5 +95,24 @@ export default {
log.error(error.message);
}
},
autogen: async () => {
const { log } = new Log('autogen');
try {
new CronJob(AUTOGEN.CRON, async () => {
const { autogen } = state.get();
if (!autogen) {
log.verbose('paused');
return;
}
const openai = (await import('../ai/openai')).default;
const summary = await new openai().random({
prompt: AUTOGEN.PROMPT,
context: AUTOGEN.KEYWORDS.join(', '),
});
emitter.emit('summary.create', summary);
}).start();
} catch (error: any) {
log.error(error.message);
}
},
};
1 change: 1 addition & 0 deletions api/src/util/state.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
let STATE: { [name: string]: any } = {
processing: false,
cron: true,
autogen: false,
image: {
index: 0,
summary: true,
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/views/ControllerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const getRandomSummary = async () => {
}
};
const toggle = async (key: 'cron' | 'mic' | 'summary') => {
const toggle = async (key: 'cron' | 'mic' | 'summary' | 'autogen') => {
if (key === 'cron') {
socket.emit('state:patch', { cron: state.value.cron });
toast.add({
Expand Down Expand Up @@ -115,6 +115,14 @@ const toggle = async (key: 'cron' | 'mic' | 'summary') => {
life: 3000,
});
}
if (key === 'autogen') {
socket.emit('state:patch', { to: 'controller', autogen: state.value.autogen });
toast.add({
severity: 'info',
detail: `Autogen Processing ${state.value.autogen ? 'Enabled' : 'Disabled'}`,
life: 3000,
});
}
};
const imageControl = (task: 'prev' | 'next' | 'toggle') => {
Expand Down

0 comments on commit 46d41b2

Please sign in to comment.