Code Monkey home page Code Monkey logo

project_ai_mern_image_generation's Introduction

project_ai_mern_image_generation's People

Contributors

adrianhajdin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project_ai_mern_image_generation's Issues

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined

I GOT GET http://127.0.0.1:5173/favicon.ico 404 (Not Found) problem, but the server shows UnhandledPromiseRejectionWarning problem.

Please somebody help to solve my problem, thanks.

(node:4048) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
at file:///F:/projects/starlink/server/routes/dalleRoutes.js:34:45
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:4048) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4048) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: connect ETIMEDOUT 64.13.192.74:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '64.13.192.74',
port: 443,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},

CORS ERROR

I am getting CORS error. 'Access-Control-Allow-Origin' header is present on the requested resource. I also tried switching browsers but it doesn't help. Please let me know if anyone has figured it out

Screenshot 2023-04-09 162719

Error on final step of deploying back-end on Render

Once I press 'Deploy Latest Commit' the deployment starts.
All goes well (Part1.png) until it tries to start the server which follows an error (Part2.png) that I do not know how to solve.
Edit: I would like to add that running the server in VS Code works perfectly. But not here on Render.

Feb 8 03:58:22 PM [nodemon] 2.0.20
Feb 8 03:58:22 PM [nodemon] to restart at any time, enter rs
Feb 8 03:58:22 PM [nodemon] watching path(s): .
Feb 8 03:58:22 PM [nodemon] watching extensions: js,mjs,json
Feb 8 03:58:22 PM [nodemon] starting node index index.js
Feb 8 03:58:24 PM internal/process/esm_loader.js:74
Feb 8 03:58:24 PM internalBinding('errors').triggerUncaughtException(
Feb 8 03:58:24 PM ^
Feb 8 03:58:24 PM
Feb 8 03:58:24 PM Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/opt/render/project/src/server/mongodb/models/post.js' imported from /opt/render/project/src/server/routes/postRoutes.js
Feb 8 03:58:24 PM at finalizeResolution (internal/modules/esm/resolve.js:276:11)
Feb 8 03:58:24 PM at moduleResolve (internal/modules/esm/resolve.js:699:10)
Feb 8 03:58:24 PM at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
Feb 8 03:58:24 PM at Loader.resolve (internal/modules/esm/loader.js:88:40)
Feb 8 03:58:24 PM at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
Feb 8 03:58:24 PM at ModuleWrap. (internal/modules/esm/module_job.js:56:40)
Feb 8 03:58:24 PM at link (internal/modules/esm/module_job.js:55:36) {
Feb 8 03:58:24 PM code: 'ERR_MODULE_NOT_FOUND'
Feb 8 03:58:24 PM }
Feb 8 03:58:24 PM [nodemon] app crashed - waiting for file changes before starting...

Part1
Part2

Image not generated but got imgUrl

I am able to generate imageUrl but image is not being displayed. This might be due to whitelisting. If thats the reason, then someone please suggest me how to whitelist my host in dalle.

image

Error Running NPM Run Dev

VITE v4.0.4 ready in 407 ms

โžœ Local: http://localhost:5173/
โžœ Network: use --host to expose
โžœ press h to show help
Failed to resolve import "./assets/react.svg" from "src\App.jsx". Does the file exist?
1:53:32โ€ฏp.m. [vite] Internal server error: Failed to resolve import "./assets/react.svg" from "src\App.jsx". Does the file exist?
Plugin: vite:import-analysis
File: C:/Users/Zach Non Admin/Desktop/dalle_clone/client/src/App.jsx:2:22
16 | var _s = $RefreshSig$();
17 | import { useState } from "react";
18 | import reactLogo from "./assets/react.svg";
| ^
19 | import "./App.css";
20 | function App() {
at formatError (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41235:46)
at TransformContext.error (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41231:19)
at normalizeUrl (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39540:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async TransformContext.transform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39673:47)
at async Object.transform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41506:30)
at async loadAndTransform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39313:29)

warn - The content option in your Tailwind CSS configuration is missing or empty.
warn - Configure your content sources or your generated CSS will be missing styles.
warn - https://tailwindcss.com/docs/content-configuration

Then when I click on the server:

1:54:21โ€ฏp.m. [vite] Internal server error: Failed to resolve import "./assets/react.svg" from "src\App.jsx". Does the file exist?
Plugin: vite:import-analysis
File: C:/Users/Zach Non Admin/Desktop/dalle_clone/client/src/App.jsx:2:22
16 | var _s = $RefreshSig$();
17 | import { useState } from "react";
18 | import reactLogo from "./assets/react.svg";
| ^
19 | import "./App.css";
20 | function App() {
at formatError (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41235:46)
at TransformContext.error (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41231:19)
at normalizeUrl (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39540:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async TransformContext.transform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39673:47)
at async Object.transform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41506:30)
at async loadAndTransform (file:///C:/Users/Zach%20Non%20Admin/Desktop/dalle_clone/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39313:29) (x2)

Npm start is not working

pm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\admin\AppData\Local\npm-cache_logs\2023-02-10T17_01_01_797Z-debug-0.log

This is the eroor
How to fix it?

cant start the server

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users*\Desktop\coding*\Dalle\server\routes\postRoutes.js' imported from C:\Users*\Desktop\coding***\Dalle\server\index.js
at new NodeError (node:internal/errors:400:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:842:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.13.0
[nodemon] app crashed - waiting for file changes before starting...

Cannot see shared images on home page

Hello, I cannot see the images after I share them with the community on the home page. It says that the action was a success however, I cannot see them listed on the home page.

Screenshot 2023-02-06 at 6 23 28 PM

Screenshot 2023-02-06 at 6 23 36 PM

TypeError: Failed to fetch + POST https://localhost:8080/api/v1/dalle net::ERR_SSL_PROTOCOL_ERROR (CreatePost.jsx:31)

@TidbitsJS

Whenever I try to generate an image, I get an alert error (TypeError: Failed to fetch) and an error in the console log (POST https://localhost:8080/api/v1/dalle net::ERR_SSL_PROTOCOL_ERROR). I know that both of these are for my generatingImg function.

const generateImage = async () => {
    if (form.prompt) {
      try {
        setGeneratingImg(true);
        const response = await fetch('https://localhost:8080/api/v1/dalle', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            prompt: form.prompt,
          }),
        });
        console.log(response)
        const data = await response.json();
        setForm({ ...form, photo: `data:image/jpeg;base64,${data.photo}` });
      } catch (err) {
        alert(err);
      } finally {
        setGeneratingImg(false);
      }
    } else {
      alert('Please provide proper prompt');
    }
  };

I was able to generate images before but not render them on the home page after sharing, so I searched a bit and made some middleware changes to allow that. However, that seemed to break my code so I went back to the original place where the images were at least generating. But, as you can see, even that is not happening now. Since a lot of your comments on the video suggested it may have something to do with the API key, I've replaced mine with a new one too.

Here's my GitHub code: https://github.com/AnukratiMehta/image-generation.git

Please let me know how I can fix this issue. TIA!

API calls not processing

I cant get my program to call OpenAPI and generate an image. This is the resultant that Im getting
image

how can I solve this?

Error: connect ETIMEDOUT 104.18.7.192:443 at TCPConnectWrap.afterConnect

ERROR ON BACKEND TERMINAL -----
[nodemon] 2.0.22
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node index index.js
Server has started on port http://localhost:8080
connected to mongodb Database
Error: connect ETIMEDOUT 104.18.7.192:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.18.7.192',
port: 443,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, /',
'Content-Type': 'application/json',
'User-Agent': 'OpenAI/NodeJS/3.2.1',
Authorization: 'Bearer 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',
'Content-Length': 73
},
method: 'post',
data: '{"prompt":"beach ","n":1,"size":"1024x1024","response_format":"b64_json"}',
url: 'https://api.openai.com/v1/images/generations'
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError],
socket: [Function: handleRequestSocket]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: 10485760,
protocol: 'https:',
path: '/v1/images/generations',
method: 'POST',
headers: [Object],
agent: undefined,
agents: [Object],
auth: undefined,
hostname: 'api.openai.com',
port: null,
nativeProtocols: [Object],
pathname: '/v1/images/generations'
},
_ended: false,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 73,
_requestBodyBuffers: [ [Object] ],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: false,
_headerSent: true,
socket: [TLSSocket],
_header: 'POST /v1/images/generations HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'Content-Type: application/json\r\n' +
'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
'Authorization: Bearer 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\r\n' +
'Content-Length: 73\r\n' +
'Host: api.openai.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'POST',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/v1/images/generations',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'api.openai.com',
protocol: 'https:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'https://api.openai.com/v1/images/generations',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}

####################################################################
I'm able to fetch image from openAi but when i click on share with community button
getting this error on backend and on console
image

image
latest image doent display in this page
##################################
PLEASE HELP ME TO RESOLVE THIS

Photo is not add to home/community

I got stuck at share with community point . JSM sir I follow this whole tutorial but after click surprise me then generating photo but when I click on share it community button then I am come back to home page with a only loading not photo is add to the community. And that loader is continues loading and loading .pls help me sir .

Error: Failed to fetch when generating an image

I can't move onto further steps because of this issue, someone please resolve this..

dalleRoutes.js

import express from 'express';
import * as dotenv from 'dotenv';
import { Configuration, OpenAIApi } from 'openai';

dotenv.config();

const router = express.Router();

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

router.route('/').get((req, res) => {
res.send('Hello from DALL-E!' );
});

router.route('/').post(async (req, res) => {
try {
const { prompt } = req.body;

const aiResponse = await openai.createImage({
  prompt,
  n: 1,
  size: '1024x1024',
  response_format: 'b64_json'
});

const image = aiResponse.data.data[0].b64_json;
res.status(200).json({ photo: image });

} catch (error) {
console.error(error);
res.status(500).send(error?.response.data.error.message);
}
});

export default router;

CreatePost.jsx
const generateImage = async () => {
if (form.prompt) {
try {
setGeneratingImg(true);
const response = await fetch('http://localhost:8080/api/v1/dalle', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
prompt: form.prompt,
}),
})

    const data = await response.json();
    setForm({ ...form, photo: `data:image/jpeg;base64,${data.photo}` })
  } catch (error) {
    alert(error);
  } finally {
    setGeneratingImg(false);
  }
} else {
  alert('Please provide proper prompt')
}

}

image

Redundant Connection to MongoDB Atlas instance?

Since we are not storing the images along with its relevant data in the MongoDB Atlas instance and instead storing them using the cloudinary service, isn't the connection to the MongoDB instance redundant as cloudinary acts as the database in this case?

Cannot see Images on homepage

Hello there,

I cannot get my images to appear on the homepage. I'm guessing the problem is coming from api/v1/posts api because when I open my terminal that is the problem that arrises. Can someone help me in fixing this?
Screenshot (42)
Screenshot (41)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.