|
| 1 | +import Layout from "@/components/Layout"; |
| 2 | +import Button from "@/components/Common/button"; |
| 3 | +import Section from "@/components/Common/section"; |
| 4 | +import Alert from "@/components/Common/alert"; |
| 5 | +import ThemePlatformIcon from "@/components/Common/themeIcons" |
| 6 | +import Tabs from "@/components/Common/tab"; |
| 7 | +import Step from "@/components/Common/step"; |
| 8 | +import Card from "@/components/Common/card"; |
| 9 | +import Important from "@/components/Common/important"; |
| 10 | +import Highlight from "@/components/Common/highlight"; |
| 11 | +import Link from "next/link"; |
| 12 | +import PlatformIcon from "@/components/Common/icons"; |
| 13 | +import HighlightTabs from "@/components/Common/HighlightTabs"; |
| 14 | +import IconContainer from "@/components/Common/IconContainer"; |
| 15 | +import { |
| 16 | + GoContainer, |
| 17 | + GoDatabase, |
| 18 | + GoRocket, |
| 19 | + GoServer, |
| 20 | + GoMail, |
| 21 | + GoGlobe, |
| 22 | + GoArrowLeft, |
| 23 | + GoTelescope, |
| 24 | +} from "react-icons/go"; |
| 25 | + |
| 26 | +import Head from "next/head"; |
| 27 | + |
| 28 | +<Layout> |
| 29 | +<Head> |
| 30 | +<title>مستندات تولید تصویر با مدل های هوش مصنوعی - لیارا</title> |
| 31 | +<meta property="og:title" content="مستندات خدمات رایانش ابری لیارا" /> |
| 32 | +<meta property="og:description" content="مستندات مربوط به نحوه تولید تصویر یا همان image generation با استفاده از مدلهای تولید عکس هوش مصنوعی لیارا" /> |
| 33 | +</Head> |
| 34 | + |
| 35 | + |
| 36 | +# نحوه تولید تصویر با هوش مصنوعی |
| 37 | +<hr className="mb-2" /> |
| 38 | + |
| 39 | +طبق <a href="https://www.cloudflare.com/learning/ai/ai-image-generation/" className="text-[#2196f3]">مستندات موجود در Cloudflare</a>، |
| 40 | +هوش مصنوعی تولید تصویر یا AI image generation نوعی از <a href="/ai/foundations/overview/#generative-artificial-intelligence" className="text-[#2196f3]">هوش مصنوعی مولد</a> است که برای خلق محتوای دیداری به کار میرود. |
| 41 | +<div className="h-2" /> |
| 42 | + |
| 43 | +این فناوری با استفاده از تحلیلهای ریاضی، الگوهای موجود در تصاویر و نگارهها را شناسایی و تکرار میکند. به بیان سادهتر، هوش مصنوعی تولید تصویر، تصاویر را بر اساس مجموعهای از نمونهها ایجاد میکند. |
| 44 | +<hr className="mb-2" /> |
| 45 | + |
| 46 | +<Section id='what-is-ai-image-generation' title='هوش مصنوعی تولید تصویر چیست؟' /> |
| 47 | + |
| 48 | +خلق تصاویر کاملاً جدید با استفاده از مدلهای هوش مصنوعی بر اساس توصیفات متنی یا پارامترهای از پیش تعیینشده. |
| 49 | + |
| 50 | +<Section id='what-is-ai-image-editing' title='هوش مصنوعی ویرایش تصویر چیست؟' /> |
| 51 | + |
| 52 | +تغییر یا بهبود تصاویر موجود با کمک الگوریتمهای هوش مصنوعی، مانند اصلاح رنگ، حذف عناصر ناخواسته یا بهبود جزئیات. |
| 53 | + |
| 54 | +<Section id='what-is-difference-between-image-generation-and-image-editing' title='تفاوت هوش مصنوعی تولید تصویر با ویرایش تصویر چیست؟' /> |
| 55 | + |
| 56 | +تولید تصویر خلق چیزی کاملاً جدید است، در حالی که ویرایش تصویر اصلاح و تغییر تصویر موجود است. |
| 57 | + |
| 58 | +<hr className="mb-2" /> |
| 59 | +<Section id='langs-and-frameworks' title='تولید تصویر در زبانها و فریمورکهای مختلف' /> |
| 60 | + |
| 61 | + <Tabs |
| 62 | + tabs={[ |
| 63 | + { |
| 64 | + label: "JavaScript", |
| 65 | + icon: <PlatformIcon platform="nodejs" style={{ width: 32, height: 32 }} />, |
| 66 | + }, |
| 67 | + { |
| 68 | + label: "Python", |
| 69 | + icon: <PlatformIcon platform="python" style={{ width: 32, height: 32 }} />, |
| 70 | + }, |
| 71 | + { |
| 72 | + label: "cURL", |
| 73 | + }, |
| 74 | + ]} |
| 75 | + content={[ |
| 76 | + |
| 77 | + <> |
| 78 | + <div className="h-2" /> |
| 79 | + <div dir='ltr'> |
| 80 | + <Highlight className="js"> |
| 81 | + {`import OpenAI from "openai"; |
| 82 | +import fs from "fs"; |
| 83 | +
|
| 84 | +const openai = new OpenAI({ |
| 85 | + baseURL: "<LIARA_BASE_URL>", |
| 86 | + apiKey: "<LIARA_API_KEY>" |
| 87 | +}); |
| 88 | +
|
| 89 | +const prompt = \`Tom Cat hugging Spike Bulldog\`; |
| 90 | +
|
| 91 | +const result = await openai.images.generate({ |
| 92 | + model: "openai/gpt-image-1", // choose your model here |
| 93 | + prompt, |
| 94 | +}); |
| 95 | +
|
| 96 | +const image_base64 = result.data[0].b64_json; |
| 97 | +const image_bytes = Buffer.from(image_base64, "base64"); |
| 98 | +fs.writeFileSync("output.png", image_bytes); |
| 99 | +`} |
| 100 | + </Highlight> |
| 101 | + </div> |
| 102 | + </>, |
| 103 | + <> |
| 104 | + <div className="h-2" /> |
| 105 | + <div dir='ltr'> |
| 106 | + <Highlight className="py"> |
| 107 | + {`from openai import OpenAI |
| 108 | +import base64 |
| 109 | +
|
| 110 | +client = OpenAI( |
| 111 | + base_url="<LIARA_BASE_URL>", |
| 112 | + api_key="<LIARA_API_KEY>" |
| 113 | +) |
| 114 | +
|
| 115 | +prompt = "Tom Cat hugging Spike Bulldog" |
| 116 | +
|
| 117 | +result = client.images.generate( |
| 118 | + model="openai/gpt-image-1", |
| 119 | + prompt=prompt |
| 120 | +) |
| 121 | +
|
| 122 | +image_base64 = result.data[0].b64_json |
| 123 | +image_bytes = base64.b64decode(image_base64) |
| 124 | +
|
| 125 | +with open("output.png", "wb") as f: |
| 126 | + f.write(image_bytes)`} |
| 127 | + </Highlight> |
| 128 | + </div> |
| 129 | + </>, |
| 130 | + |
| 131 | + <> |
| 132 | + <div className="h-2" /> |
| 133 | + <div dir='ltr'> |
| 134 | + <Highlight className="bash"> |
| 135 | + {`curl <LIARA_BASE_URL>/images/generations \\ |
| 136 | + -H "Content-Type: application/json" \\ |
| 137 | + -H "Authorization: Bearer <LIARA_API_KEY>" \\ |
| 138 | + -d '{ |
| 139 | + "model": "openai/gpt-image-1-mini", |
| 140 | + "prompt": "A cute baby sea otter", |
| 141 | + "n": 1, |
| 142 | + "size": "1024x1024", |
| 143 | + "quality": "high" |
| 144 | +}'`} |
| 145 | + </Highlight> |
| 146 | + </div> |
| 147 | + </>, |
| 148 | + ]} |
| 149 | + |
| 150 | + /> |
| 151 | + |
| 152 | + |
| 153 | +{/* |
| 154 | +<Section id='edit-on-langs-and-frameworks' title='ویرایش تصویر در زبانها و فریمورکهای مختلف' /> |
| 155 | +
|
| 156 | + <Tabs |
| 157 | + tabs={[ |
| 158 | + { |
| 159 | + label: "JavaScript", |
| 160 | + icon: <PlatformIcon platform="nodejs" style={{ width: 32, height: 32 }} />, |
| 161 | + }, |
| 162 | + { |
| 163 | + label: "PHP", |
| 164 | + icon: <PlatformIcon platform="php" style={{ width: 32, height: 32 }} />, |
| 165 | + }, |
| 166 | + { |
| 167 | + label: "Python", |
| 168 | + icon: <PlatformIcon platform="python" style={{ width: 32, height: 32 }} />, |
| 169 | + }, |
| 170 | + { |
| 171 | + label: "NET.", |
| 172 | + icon: <PlatformIcon platform="dotnet" style={{ width: 32, height: 32 }} />, |
| 173 | + }, |
| 174 | + { |
| 175 | + label: "Go", |
| 176 | + icon: <PlatformIcon platform="go" style={{ width: 32, height: 32 }} />, |
| 177 | + }, |
| 178 | + { |
| 179 | + label: "cURL", |
| 180 | + }, |
| 181 | + ]} |
| 182 | + content={[ |
| 183 | + |
| 184 | + <> |
| 185 | + <div className="h-2" /> |
| 186 | + <div dir='ltr'> |
| 187 | + <Highlight className="js"> |
| 188 | + {`import OpenAI from "openai"; |
| 189 | +import fs from "fs"; |
| 190 | +
|
| 191 | +const openai = new OpenAI({ |
| 192 | + baseURL: "<LIARA_BASE_URL>", |
| 193 | + apiKey: "<LIARA_API_KEY>" |
| 194 | +}); |
| 195 | +
|
| 196 | +const prompt = \`Tom Cat hugging Spike Bulldog\`; |
| 197 | +
|
| 198 | +const result = await openai.images.generate({ |
| 199 | + model: "openai/gpt-image-1", // choose your model here |
| 200 | + prompt, |
| 201 | +}); |
| 202 | +
|
| 203 | +const image_base64 = result.data[0].b64_json; |
| 204 | +const image_bytes = Buffer.from(image_base64, "base64"); |
| 205 | +fs.writeFileSync("output.png", image_bytes); |
| 206 | +`} |
| 207 | + </Highlight> |
| 208 | + </div> |
| 209 | + </>, |
| 210 | + <> |
| 211 | + <div className="h-2" /> |
| 212 | + <div dir='ltr'> |
| 213 | + <Highlight className="js"> |
| 214 | + {``} |
| 215 | + </Highlight> |
| 216 | + </div> |
| 217 | + </>, |
| 218 | + <> |
| 219 | + <div className="h-2" /> |
| 220 | + <div dir='ltr'> |
| 221 | + <Highlight className="js"> |
| 222 | + {``} |
| 223 | + </Highlight> |
| 224 | + </div> |
| 225 | + </>, |
| 226 | + <> |
| 227 | + <div className="h-2" /> |
| 228 | + <div dir='ltr'> |
| 229 | + <Highlight className="js"> |
| 230 | + {``} |
| 231 | + </Highlight> |
| 232 | + </div> |
| 233 | + </>, |
| 234 | + <> |
| 235 | + <div className="h-2" /> |
| 236 | + <div dir='ltr'> |
| 237 | + <Highlight className="js"> |
| 238 | + {``} |
| 239 | + </Highlight> |
| 240 | + </div> |
| 241 | + </>, |
| 242 | + <> |
| 243 | + <div className="h-2" /> |
| 244 | + <div dir='ltr'> |
| 245 | + <Highlight className="js"> |
| 246 | + {``} |
| 247 | + </Highlight> |
| 248 | + </div> |
| 249 | + </>, |
| 250 | + ]} |
| 251 | +
|
| 252 | + /> |
| 253 | + */} |
| 254 | + |
| 255 | +{/* |
| 256 | +<Section id='' title='' /> |
| 257 | +<Important> |
| 258 | +</Important> |
| 259 | +<hr className="mb-2" /> |
| 260 | +<div dir='ltr'> |
| 261 | + <Highlight className="js"> |
| 262 | + {``} |
| 263 | + </Highlight> |
| 264 | +</div> |
| 265 | +<div className="h-2" /> |
| 266 | +
|
| 267 | +<div className="h-2" /> |
| 268 | +<img src="https://media.liara.ir/" alt=""/> |
| 269 | +<div className="h-2" /> |
| 270 | +
|
| 271 | +
|
| 272 | +<video |
| 273 | + src="https://media.liara.ir/" |
| 274 | + controls="controls" |
| 275 | + className="block w-full" |
| 276 | + width="100%" |
| 277 | +/> */} |
| 278 | + |
| 279 | +</Layout> |
0 commit comments