Creating an Image Generation App with PHP and OpenAI's DALL-E 2 API: Tutorial and Demo

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 17

  • @Shafty17
    @Shafty17 Рік тому

    Correct me if I'm wring but this can be done with plain js as well without php. Considering we are making simple POST request and nothing else.

    • @hacodes
      @hacodes  Рік тому

      No you cannot do that in plain JS. There is only two official libraries available in nodejs and python. Some other languages also support Open Ai with the help of community libraries. But there is no documentation for plain js. Check more on Open Ai library docs

    • @Shafty17
      @Shafty17 Рік тому

      @@hacodes Oh, thanks for clarification. I will do it for sure. Great video nevertheless.

  • @artemhladchuk
    @artemhladchuk Рік тому

    how to catch response api errors if user input illegal words?

    • @hacodes
      @hacodes  Рік тому

      You can use try catch in js it will give error in catch

  • @akirahabane4904
    @akirahabane4904 Рік тому

    The code works well. But occasionally, it would display an error of "index.html:38 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
    at http.onload (index.html:38:34)". May I ask what would be the solution to this error? Adjusting the prompts usually solve the issue, but it would be much appreciated if I can input any prompts without causing any form of error. Thank You in advance for your help~

    • @hacodes
      @hacodes  Рік тому

      Can you tell which prompt give error?

    • @akirahabane4904
      @akirahabane4904 Рік тому

      For ex. men apparel, vintage suit, front view, ulrarealistic, hyperrealistic, photo realistic would gemerate result. But say if I made it specific like men apparel, t shirt with astronaut design, front view, photorealistic, it would be 50-50. Sometimes it generates, sometimes it gives the error

  • @AlexDevSymfony
    @AlexDevSymfony Рік тому

    Merci pour ta vidéo !

  • @danielvasvari737
    @danielvasvari737 Рік тому

    This goes wrong on me. :( Any update?

    • @hacodes
      @hacodes  Рік тому

      What's the issue?

    • @danielvasvari737
      @danielvasvari737 Рік тому

      @@hacodes (index):36 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
      at http.onload ((index):36:13)

    • @danielvasvari737
      @danielvasvari737 Рік тому

      const input = document.querySelectorAll('input');
      const button = document.querySelector('button')
      const imgContainer = document.querySelector('.img-container')
      button.onclick = () => {
      if(input[0]){
      var http = new XMLHttpRequest();
      var data = new FormData();
      data.append('prompt', input[0].value + input[1].value + input[2].value)
      http.open('POST', 'request.php', true)
      http.send(data)
      http.onload = () => {
      imgContainer.innerHTML = ''
      var response = JSON.parse(http.response).data
      response.forEach(e => {
      var img = document.createElement('img')
      img.src = 'data:image/jpeg;base64,' + e.b64_json
      imgContainer.appendChild(img)
      })
      }
      }
      }

    • @hacodes
      @hacodes  Рік тому

      You are not getting response from php file, try running PHP file to check what you getting

  • @akeaditing3896
    @akeaditing3896 Рік тому

    Api is free are Not

    • @hacodes
      @hacodes  Рік тому

      Free for three month

  • @danielvasvari737
    @danielvasvari737 Рік тому +1

    I ran into a problem and spent an hour looking for a solution. If it helps someone:
    Error:
    Failed to download orhanerday/open-ai from dist: The zip extension and unzip/7z commands are both missing, skipping.
    The php.ini used by your command-line PHP is: C:\xampp\php\php.ini Now trying to download from source In GitDownloader.php line 82: git was not found in your PATH, skipping source download
    Solution:
    You will need to manually enable this extension within your php.ini (C:\xampp\php\php.ini) by adding this to extension list:
    extension=php_zip.dll