herrDeng網內搜尋

自訂搜尋

Ads

2023年3月20日 星期一

python撰寫使用openai api DALL-E產生黑柴AI假圖

 
 python撰寫使用openai api DALL-E產生黑柴AI假圖。相關python code請進。
 使用python套件openai, requests, opencv的綜合練習。 
「openai之DALL-E簡介與操作百變黑柴AI假圖」https://youtu.be/IRBmM-wO_FE 

openai還有其他試用的姊妹產品「openai之point-E操作產生3D點雲」

「使用openAI之chatGPT學習 opencv C++程式」https://youtu.be/HH4TZnRynPE
==============================================
  1. print('使用openai的api進行DALL-E AI假圖生成')
  2. !pip install openai
  3.  
  4. import openai
  5.  
  6. openai.api_key_path = "openai-key.txt"#金鑰所存放的檔案
  7.  
  8. r=openai.Image.create(
  9. prompt="2 black shiba inus driving cars in a photorealistic style",
  10. n=1,
  11. size="1024x1024"
  12. )
  13. print(r)
  14.  
  15. im=[]
  16. im.append(r["data"][0]["url"])
  17.  
#以下採requests下載AI圖
  1. import requests
  2. r0 = requests.get(im[0])
  3. if r0.status_code==200:
  4. with open('imy.png', 'wb') as f:
  5. f.write(r0.content)
#顯示圖的部份採用opencv,這在google colab上不適用
  1. import cv2
  2. x=cv2.imread('imy.png')
  3. cv2.imshow('AI image', x)
  4. cv2.waitKey(0)
  5. cv2.destroyAllWindows()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章