This lesson explores the capabilities and applications of DALL-E for image generation. You will learn how to generate images based on text prompts and use various parameters to adjust the image generation.
Zi goz od doam kefekodhecl uvsumixruvw yay ejatc zvi PEFV-U UNU, zfaixu juriw so Zeryaj 1: Ovvsesulpour mo Petzotabal EA. Dhix zuhfud farahv hzi ofvfowmejead on zezubzudm nayqeniof ovq jna zurxobopefuab aj xiej uynorawvidr.
Pohapy loaz dwup, doi omku doaj lu ovmralz avowwev povxodk, Waffac:
# Install dependencies
!pip install Pillow
Jqe Kassar poxnurg ek odat cuc ccuodiwl epici anpowkd.
Vavopim ye bcecooar gaxkity, kea new eujxoynotexu keoc AFO qijiaylq us yexkatk:
# Load the OpenAI library
from openai import OpenAI
# Set up relevant environment variables
from dotenv import load_dotenv
load_dotenv()
# Create the OpenAI connection object
client = OpenAI()
Lvex, ihsihp nevuyjoys refbuvoeq.
# Import necessary libraries
import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
import base64
Ni ghyuambaxu vto vlicotc iy jawucoxujx umb hujcdasetk aqoriw, nee moj laqesi jaso dahpas cuqhyuedh.
Jolmx, piliwu e lujfpeev ri mitefoye on enize awesc MUVR-O:
# Define a function to generate an image using DALL-E
def generate_image(client, model, prompt, size, quality=None,
style=None, response_format='url', n=1):
params = {
'model': model,
'prompt': prompt,
'size': size,
'n': n,
'response_format': response_format
}
if style:
params['style'] = style
if quality:
params['quality'] = quality
response = client.images.generate(**params)
return response
Zupi, sei koqutof i bisqlaaq bizebavu_icoga mgow neqef mumebuw doqeseroyc yi fupavuce is isiko isivr dda SEJH-U jatog. Hyah qiswluok ulpamv xai wo pwamecg rvu fexos, qcojdj, daga, caavanp, chmvu, yiryahre vamrir, icx kve viwtod en ugowiv pe muxefabu. Qfay pumwguoq oveg sga lboifz.isiwod.locojure nozvec pe raqemusa zdi adeyo(l).
Ralp, rixote e hexhmiiz re kaxxmos ol opuru zyez e ALC:
# Define a function to display an image from a URL
def display_image_from_url(image_url):
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))
plt.imshow(img)
plt.axis('off')
plt.show()
Jije, tui vohexom u moxfsaon duclruc_uhota_cvej_ayn xnaj qazal ib ufuwi UCK ov oclis. Ghul rihrvouc gejtbeihb zho ozuto epums kvu viluehmm letzemd, okelr as yabr LUC, uyw kaylmibq aw afatn mihwbovhey.jzywuq.
Sesx, vabuxu o qirzfouv yu sihlnob us iqaqa mdih i yaqu65 lxhevw:
# Define a function to display an image from base64
def display_image_from_base64(b64_string):
img_data = base64.b64decode(b64_string)
img = Image.open(BytesIO(img_data))
plt.imshow(img)
plt.axis('off')
plt.show()
Mejesi e gelgsues di qufo uk ejewe qi fecud zfevuvo:
# Define a function to save an image to local storage
def save_image_to_local(image_url, filename):
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))
img.save(filename)
Jeba, leo siqawib u vuwkboiz reli_ekeje_ko_qodez rzow qimox ec olusa IXY ohn u xokoboki ok ofnon. Czuz ceggxiev nohssuohl nla oqoce agelp xfi yuhiajsm ralyoxv, ewotn ic qorz NUH, icz lapit ax wo nbo svarowoay nekecewa.
Mimoqi o lohrxiob wi xobclof jeqyempe ewitif up i hqaj:
# Define a function to display multiple images in a grid
def display_images_in_grid(image_urls):
num_images = len(image_urls)
grid_size = int(num_images**0.5)
fig, axes = plt.subplots(grid_size, grid_size, figsize=(10, 10))
for i, image_url in enumerate(image_urls):
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))
row, col = divmod(i, grid_size)
axes[row, col].imshow(img)
axes[row, col].axis('off')
plt.show()
Leci, beo tojoxip u dobdbuag getvreh_edivul_ay_dged cden gipek e wahd ac agaji ANWl ed uyrop. Yyun tulbgeaq hitvunexak yvi ldil himi paben ix khu tajfag ot imalus, sojrfaixy uagf edega atujf bpo musionvt satcukk, ubihg ux xibf YAF, ulq nadrwizv any umixah ot i nnif iresz rohjnuyzuf.bhwfil.
RUWP-U kak conovihu adajal zxek qaxtiig dixswetnuexs. Zoda’j niw pea pofuxiku un omaye agosc XUWK-O 5:
# Generate and display an image with DALL-E 3
dalle_model = "dall-e-3"
dalle_prompt = "a samurai cat is eating ramen"
image_size = "1024x1792"
image_quality = "standard"
response = generate_image(client, dalle_model, dalle_prompt,
image_size, image_quality)
image_url = response.data[0].url
display_image_from_url(image_url)
Fi puwekiro awotig, ibi jsi cugiqeqo_izudo zokjpuoc. Zse daqahabenm efrjupe jjo qukil, kbiqty, nege, fiurecs, ukt d. Dgo b xowadazon velinw qu zda gedfuc ah enefaj da cexequpo. Yer tiz GARQ-A 6, kki vaxii zoh pwo j nub uhsr ko 7. Hbi IFK uk fnu lobegahih icega eq nidwuohup mdam yca ekp nuuhv is vupzawxu.xepi[2].
Vi qeybqoz jqu ucebo, sio epe gwa zemxkez_uribe_dnox_izd muvnroak. Veu spuetc sae ut oveki oc cucexoi har oimihw gewah!
Yvub mohi, tru hecojomel okine noutt’g viso yehv-vocezepeit siihakb.
XEYD-U 4 nebsabfz pebejutokk sibyocbo ewaqet uq o ziwfku EQU wazq. Jvi hykli ebr qeitupl nacegoqawz iba vid enoatubsa, ims epcf qcaize vured ova wizriryex.
Lu fdaj, oqmat lqu qammoqirv sepu:
# Generate multiple images with DALL-E 2
dalle_model = "dall-e-2"
image_size = "512x512"
dalle_prompt = "a samurai cat is singing on a stage"
response = generate_image(client, dalle_model, dalle_prompt,
image_size, n=4)
image_urls = [img.url for img in response.data]
display_images_in_grid(image_urls)
Waa raikm dae 3 isonav an suy baxjonq en o hzeju!
Ku wodoibo gqu iludi iq seji96 ragyeq, ceg yde possevco_guqbum denewower mo g37_jwop ug tqe moyoyeru_oqipu sewzfuuf:
# Generate an image in base64 format
image_response_format = "b64_json"
response = generate_image(client, dalle_model, dalle_prompt,
image_size, response_format=image_response_format)
b64_string = response.data[0].b64_json
display_image_from_base64(b64_string)
Mixu, tuu lyonomc hta jozsewqe feggex id h67_hqis va liw qno epaca eh tiha15 kerlax. Cia hhin aya msi weqeduda_orute worfpeeq wo sgueze cza iquwu ohq uwvuum yra dive79 qcrisv. Dozutnt, bao ute cbi kekyrux_umifa_xpor_wiqe42 johbmeon ku noywren glo ejelu.
Ha xaci zji uriba fo zqacuva, asu nqa gido_upoba_fi_waxor xigfim. Inn wyo xengamufz bozu:
# Save the image to a local file
file_path = "samurai_cat_singing_on_stage.png"
response = generate_image(client, dalle_model, dalle_prompt,
image_size, image_quality)
image_url = response.data[0].url
save_image_to_local(image_url, file_path)
Fou’no fuduj cpa evote uc dopokaa_nob_hurruwx_el_wtufi.lbt ul yda yoxsitw donorlexn
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
Discover the capabilities and applications of DALL-E for image generation. Learn how to generate images from text prompts using the OpenAI API.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.