Spaces:
Build error
Build error
| 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) | |