Skip to content

Commit

Permalink
feat: extended text to image (blib-la#192)
Browse files Browse the repository at this point in the history
## Motivation

<!-- List motivation and changes here -->

## Issues closed

<!-- List closed issues here -->
  • Loading branch information
pixelass committed Apr 9, 2024
1 parent 94e38d7 commit a2c4d6e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 65 deletions.
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -37,10 +37,10 @@
"sharp": "0.33.2"
},
"devDependencies": {
"@captn/joy": "^0.14.0",
"@captn/react": "^0.14.0",
"@captn/theme": "^0.14.0",
"@captn/utils": "^0.14.0",
"@captn/joy": "^0.15.0",
"@captn/react": "^0.15.0",
"@captn/theme": "^0.15.0",
"@captn/utils": "^0.15.0",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@dnd-kit/core": "^6.1.0",
Expand Down
55 changes: 26 additions & 29 deletions resources/actions/explorer/readme.md
Expand Up @@ -7,38 +7,35 @@ type: app
path: /en/apps/explorer
creatorID: Blibla
tags:
- art discovery
- literature generation
- photo filtering
- novel narratives
- picture sorting
- image search
- story crafting
- artistic modeling
- explorer
- finder
- search
- files
license: AGPL 3.0
accessLevel: public
description: "Dive into your media library with Creative Explorer. Harness AI to filter, search, and craft stories from your photos, art, and text."
description: "Dive into your media library with Creative Explorer."
icon: Folder
iconColor: "#6C5EF5"
---

Filter art by era or style.
Search for poetry in your pictures.
Discover novels in photo sequences.
Show narratives hidden within snapshots.
Find literature connecting your images.
Craft tales from scenic photographs.
Generate stories from daily photos.
Explore thematic collections of art pieces.
Reveal historical narratives in family albums.
Unveil the novel within your gallery.
Sort images by emotional impact.
Connect pictures into a visual novel.
Search for patterns in artistic compositions.
Find photos matching a literary theme.
Craft biographies from portrait galleries.
Generate documentaries from event images.
Reveal the artistry in candid snapshots.
Uncover mysteries told through archived pictures.
Explore generative art models for photo enhancement.
Navigate through the chapters of your visual story.
Launch the explorer to browse my documents.
Show me how to access the finder for photos.
Open the file explorer to manage my folders.
Guide me to open the finder for organizing files.
Command to launch the explorer for viewing images.
How do I start the explorer with a keyboard shortcut?
Open my documents directly in the file explorer.
Find steps to access external storage in the finder.
Shortcut to open the downloads folder in the explorer.
Launch the explorer to search for specific file names.
Discover the quickest way to open recent items in the finder.
Open the explorer at a particular directory for quick access.
Use search commands to open specific folders in the explorer.
Navigate to my cloud files directly through the finder.
Tips for opening and managing files with the explorer.
Access shared documents through the explorer.
Open multiple finder windows for efficient file management.
Reveal hidden items on the first launch of the explorer.
Employ search functionalities in the finder for specific queries.
Organize and search for specific content using the explorer.

25 changes: 21 additions & 4 deletions resources/python/stable-diffusion/text-to-image/main.py
Expand Up @@ -245,6 +245,7 @@ def warmup(pipe):
for _ in range(6):
pipe(
prompt="the moon, 4k",
negative_prompt="nsfw, nude",
height=1024,
width=1024,
num_inference_steps=1,
Expand All @@ -257,14 +258,20 @@ def warmup(pipe):
def main(pipe, output_image_path, shutdown_event):
# Initial/default values for parameters
prompt = "a captain with white beard, teal hat and uniform"
negative_prompt = "nsfw, nude"
seed = 1
steps = 20
guidance_scale = 7.0
height = 1024
width = 1024

last_prompt = prompt
last_negative_prompt = negative_prompt
last_seed = seed
last_steps = steps
last_guidance_scale = guidance_scale
last_height = height
last_width = width

# Queue to hold parameters received from stdin
params_queue = queue.Queue()
Expand All @@ -281,9 +288,12 @@ def main(pipe, output_image_path, shutdown_event):
while not params_queue.empty():
parameters = params_queue.get_nowait()
prompt = parameters.get("prompt", prompt)
negative_prompt = parameters.get("negative_prompt", negative_prompt)
seed = parameters.get("seed", seed)
guidance_scale = parameters.get("guidance_scale", guidance_scale)
steps = parameters.get("steps", steps)
guidance_scale = parameters.get("guidance_scale", guidance_scale)
height = parameters.get("height", height)
width = parameters.get("width", width)
print(f"Updated parameters {parameters}")
except queue.Empty:
pass # No new parameters, proceed with the existing ones
Expand All @@ -292,16 +302,22 @@ def main(pipe, output_image_path, shutdown_event):
# Determine if image generation should be triggered
trigger_generation = (
prompt != last_prompt
or negative_prompt != last_negative_prompt
or seed != last_seed
or steps != last_steps
or guidance_scale != last_guidance_scale
or height != last_height
or width != last_width
)

if trigger_generation:
last_prompt = prompt
last_negative_prompt = negative_prompt
last_seed = seed
last_steps = steps
last_guidance_scale = guidance_scale
last_height = height
last_width = width

# Only generate an image if the prompt is not empty
if prompt is not None and prompt.strip():
Expand All @@ -310,9 +326,10 @@ def main(pipe, output_image_path, shutdown_event):
guidance_scale_ = float(guidance_scale)

image = pipe(
prompt,
height=1024,
width=1024,
prompt=prompt,
negative_prompt=negative_prompt,
height=height,
width=width,
num_inference_steps=steps,
num_images_per_prompt=1,
strength=1.0,
Expand Down
1 change: 1 addition & 0 deletions src/client/apps/story/index.tsx
Expand Up @@ -71,6 +71,7 @@ export function Story() {

const { data: images_ } = useVectorScroll({
with_payload: true,
limit: 100,
filter: { must: [{ key: "type", match: { value: "image" } }] },
});

Expand Down
2 changes: 1 addition & 1 deletion src/client/pages/[locale]/apps/explorer.tsx
Expand Up @@ -101,7 +101,7 @@ export function PreviewIcon({ item }: { item: VectorStoreResponse }) {
export default function Page(_properties: InferGetStaticPropsType<typeof getStaticProps>) {
const { t } = useTranslation(["common", "labels"]);
const [query, setQuery] = useState("");
const { data } = useVectorStore(query);
const { data } = useVectorStore(query, { limit: 100, score_threshold: 0.2 });

const uniqueData = useMemo(() => uniqBy(data, "payload.id"), [data]);
const groups = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/client/pages/[locale]/apps/story.tsx
Expand Up @@ -23,7 +23,7 @@ export default function Page(_properties: InferGetStaticPropsType<typeof getStat
}
>
<Head>
<title>{t("labels:livePainting")}</title>
<title>{t("labels:createStory")}</title>
</Head>
<Box sx={{ position: "absolute", inset: 0, display: "flex", flexDirection: "column" }}>
<Story />
Expand Down
4 changes: 2 additions & 2 deletions src/electron/future/ipc/global.ts
Expand Up @@ -125,7 +125,7 @@ ipcMain.handle(
context?: string
) => {
const filePath = getCaptainData("files", subpath);
const { dir: directory, ext } = path.parse(filePath);
const { dir: directory, ext, base } = path.parse(filePath);
const fileType = getFileType(filePath);

// Ensure the directory exists, creating it if necessary
Expand Down Expand Up @@ -193,7 +193,7 @@ ipcMain.handle(
content: context ?? content,
payload: {
id,
label,
label: base,
type: fileType,
fileType: ext.replace(".", ""),
language: "en",
Expand Down
3 changes: 1 addition & 2 deletions src/electron/future/main.ts
Expand Up @@ -224,8 +224,7 @@ for (const installedApp of installedApps) {

appLoaders[id] = serve({
directory: getCaptainData(`apps`, id),
scheme: "captn",
hostname: id,
scheme: `captn-${id}`,
file: "index",
});
}
Expand Down

0 comments on commit a2c4d6e

Please sign in to comment.