Skip to content

Commit

Permalink
use lora mode
Browse files Browse the repository at this point in the history
  • Loading branch information
genekogan committed Jan 8, 2025
1 parent 4009a52 commit e3e05a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions eve/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Model(Document):
checkpoint: str
base_model: str
lora_trigger_text: Optional[str] = None
lora_model: Optional[str] = None

# users: SkipJsonSchema[Optional[Collection]] = Field(None, exclude=True)

Expand Down
32 changes: 22 additions & 10 deletions eve/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async def generate_lora_thumbnails():

try:
tool = Tool.load(key="flux_dev_lora")
prompts = await generate_prompts()
lora_mode = model.get("lora_mode")
prompts = await generate_prompts(lora_mode)
thumbnails = []

for prompt in prompts:
Expand Down Expand Up @@ -145,22 +146,37 @@ async def generate_thumbnail():
traceback.print_exc()


async def generate_prompts():
sampled_prompts = random.sample(ALL_PROMPTS, 16)
prompt_examples = [{"prompts": sampled_prompts[i:i+4]} for i in range(0, 16, 4)]

async def generate_prompts(lora_mode: str = None):
if lora_mode == "face":
sampled_prompts = random.sample(FACE_PROMPTS, 16)
elif lora_mode == "object":
sampled_prompts = random.sample(OBJECT_PROMPTS, 16)
elif lora_mode == "style":
sampled_prompts = random.sample(STYLE_PROMPTS, 16)
else:
sampled_prompts = random.sample(ALL_PROMPTS, 16)

class Prompts(BaseModel):
"""Exactly FOUR prompts for image generation models about <Concept>"""
prompts: List[str] = Field(..., description="A list of 4 image prompts about <Concept>")

model_config = ConfigDict(
json_schema_extra={
"examples": prompt_examples
"examples": [
{"prompts": sampled_prompts[i:i+4]} for i in range(0, 16, 4)
]
}
)

prompt = """Come up with exactly FOUR (4, no more, no less) detailed and visually rich prompts about <Concept>. These will go to image generation models to be generated. Prompts must contain the word <Concept> at least once, including the angle brackets."""

if lora_mode == "face":
prompt += " The concept refers to a specific person."
elif lora_mode == "object":
prompt += " The concept refers to a specific object or thing."
elif lora_mode == "style":
prompt += " The concept refers to a specific style or aesthetic."

try:
client = instructor.from_openai(openai.AsyncOpenAI())
result = await client.chat.completions.create(
Expand Down Expand Up @@ -256,7 +272,3 @@ class Prompts(BaseModel):
]

ALL_PROMPTS = FACE_PROMPTS + OBJECT_PROMPTS + STYLE_PROMPTS


# if __name__ == "__main__":
# asyncio.run(generate_lora_thumbnails())

0 comments on commit e3e05a5

Please sign in to comment.