File size: 2,412 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
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
{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "Picture generations\n",
   "id": "d93a01c4260ba9d2"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from together import Together\n",
    "import os\n",
    "from langchain_together import ChatTogether\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()\n",
    "import base64\n",
    "\n",
    "client = Together()\n",
    "\n",
    "getDescriptionPrompt = \"what is in the image? describe in detail\"\n",
    "\n",
    "imagePath = \"pics/IMG_3651.jpg\"\n",
    "\n",
    "\n",
    "def encode_image(image_path):\n",
    "    with open(image_path, \"rb\") as image_file:\n",
    "        return base64.b64encode(image_file.read()).decode('utf-8')\n",
    "\n",
    "\n",
    "base64_image = encode_image(imagePath)\n",
    "\n",
    "stream = client.chat.completions.create(\n",
    "    # model=\"meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo\",\n",
    "    model=\"meta-llama/Llama-Vision-Free\",\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\"type\": \"text\", \"text\": getDescriptionPrompt},\n",
    "                {\n",
    "                    \"type\": \"image_url\",\n",
    "                    \"image_url\": {\n",
    "                        \"url\": f\"data:image/jpeg;base64,{base64_image}\",\n",
    "                    },\n",
    "                },\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    "    stream=False,\n",
    ")\n",
    "prompt = stream.choices[0].message.content\n",
    "\n",
    "response = client.images.generate(\n",
    "    prompt=prompt,\n",
    "    model=\"black-forest-labs/FLUX.1-schnell-Free\",\n",
    "    steps=4,\n",
    "    n=4\n",
    ")\n",
    "print(response.data[0].url)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}