File size: 1,609 Bytes
45b200f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from together import Together
import os
from langchain_together import ChatTogether
from dotenv import load_dotenv
load_dotenv()
import base64
#%%
client = Together()

getDescriptionPrompt = "what is in the image? describe in detail"

imagePath= "pics/IMG_3651.jpg"

def encode_image(image_path):
        with open(image_path, "rb") as image_file:
            return base64.b64encode(image_file.read()).decode('utf-8')

base64_image = encode_image(imagePath)

stream = client.chat.completions.create(
    # model="meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
    model="meta-llama/Llama-Vision-Free",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": getDescriptionPrompt},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{base64_image}",
                    },
                },
            ],
        }
    ],
    stream=False,
)
#%%
prompt = stream.choices[0].message.content
#%%
client = Together()
response = client.images.generate(
    prompt=prompt,
    model="black-forest-labs/FLUX.1-schnell-Free",
    steps=4,
    n=4
)
print(response.data[0].url)

# ---

# from together import Together
# import os
# from langchain_together import ChatTogether
# from dotenv import load_dotenv
# load_dotenv()
#
# client = Together()
# response = client.images.generate(
#     prompt="Cats fighting boats with atomic bombs",
#     model="black-forest-labs/FLUX.1-schnell-Free",
#     steps=4,
#     n=4
# )
# print(response.data[0].url)