File size: 3,267 Bytes
7e85237
 
6a7f780
 
7e85237
 
6a7f780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e85237
 
6a7f780
 
 
 
 
 
 
 
 
7e85237
6a7f780
 
 
 
 
 
 
 
 
 
 
 
 
 
7e85237
70aa23a
 
 
 
 
 
 
 
 
 
 
 
 
 
6a7f780
 
 
70aa23a
 
 
 
 
 
 
 
 
6a7f780
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from openai import OpenAI
import base64
from model_player import Player

client = OpenAI()


def get_ai_response(prompt):
    response = client.responses.create(
        model="gpt-4o-mini",
        input=prompt
    )
    return response.output_text


def generate_image(prompt):
    result = client.images.generate(
        model="gpt-image-1",
        size="1024x1024",
        quality="medium",
        prompt=prompt
    )
    image_base64 = result.data[0].b64_json
    image_bytes = base64.b64decode(image_base64)
    return image_bytes


prompt_a = """
You are generating a realistic portrait of a fictional professional soccer player using their structured profile data.

Use the information below to inform the player's:
- Physical build (age, height, weight)
- Facial features and vibe (bio, nationality, personality)
- Team kit details (team name, role, position)
- Pose and mood (based on form, rating, injury status)

Be creative, but grounded in realism — think press photo or matchday portrait.

Here is the player profile:

{player_profile}

Your output should describe only the image to be generated. No text, captions, or extra commentary. Just a detailed image prompt.
"""

# result = client.images.generate(
#     model="gpt-image-1",
#     size="1024x1024",
#     quality="medium",
#     prompt=prompt
# )

# image_base64 = result.data[0].b64_json
# image_bytes = base64.b64decode(image_base64)

# # Generate profile pic descriptions for all players
# for player in Player.get_players():
#     print(player.name)
#     # print(player.profile_pic)
#     if not player.profile_pic:
#         print("--> generate pic description")
#         text = prompt_a.format(player_profile=player.model_dump())
#         response = get_ai_response(text)
#         print(response)
#         player.profile_pic = response
#         player.save()
#     else:
#         print("--> skip")
#     # break


image_prompt = """
A realistic studio-style headshot portrait of {profile[name]}, a {profile[age]}-year-old professional soccer player from {profile[nationality]}. He plays as a {profile[position]} and currently wears jersey number {profile[shirt_number]} for the {team_name} soccer team. 

He is wearing the team's official kit: a {shirt_color} jersey, clean and well-fitted, featuring his number {profile[shirt_number]} on the front. The image should capture a calm and confident expression, suitable for official media. The player has a well-groomed appearance, facing forward with even lighting and a neutral or softly blurred backdrop in studio conditions. No action pose, just a clear, professional profile suitable for player bio pages or trading cards.
"""

shirt_colors = {
    "Everglade FC": "emerald green",
    "Fraser Valley United": "dark red",
    "Yucatan Force": "dark orange",
    "Tierra Alta FC": "spring green",
}

# Generate images for all players
for player in Player.get_players():
    print(player.name)
    # print(player.player_info())
    shirt_color = shirt_colors[player.team]
    text = image_prompt.format(
        profile=player.player_info(),
        team_name=player.team,
        shirt_color=shirt_color)
    # print(text)
    # print(player.profile_pic)
    response = generate_image(text)
    player.save_image(response)