Spaces:
Runtime error
Runtime error
File size: 1,239 Bytes
55d5517 1bc7525 a46217d 1bc7525 a46217d 1bc7525 788a6f6 1bc7525 a46217d 1bc7525 788a6f6 1bc7525 55d5517 1bc7525 391b2d9 788a6f6 739e67a 28e7d81 1bc7525 28e7d81 1bc7525 a46217d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import json
import re
from typing import Dict, List
from ai import llm
from utils.io import print_system
PROMPT = """
Your goal is to find the best image that can be used as an ad for a website.
The ad must have certain dimensions but the image can be edited or cut.
So you must consider an image that is suited to fit those dimensions after editing.
You should consider the content of the website. The content of the images has been labeled.
You will create a headline for the ad.
Summary of the website:
{summary}
Image urls, with labels and dimensions:
{image_infos}
Dimensions for the ad: {dimensions}.
Use the following format.
```
{{
"reason": Why the image was chosen
"url":
"headline"":
"original_domensions": The image's dimensions
}}
```
"""
def get_headline_for_image(
summary: str, dimensions: str, image_infos: List[Dict]
) -> str:
return _get_headline_for_image(
PROMPT, summary=summary, dimensions=dimensions, image_infos=image_infos
)
def _get_headline_for_image(prompt: str, **kwargs) -> str:
print_system("Generating ad from images...")
instructions = prompt.format(**kwargs)
messages = [{"role": "user", "content": instructions}]
return llm.next(messages)
|