-
Notifications
You must be signed in to change notification settings - Fork 123
feat : add node function to generate images with gemini #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
imnb57
wants to merge
14
commits into
appwrite:main
Choose a base branch
from
imnb57:gemini-image-generation-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a1af360
feat : add function to generate images with gemini
imnb57 c05084a
feat : add function to generate images with gemini
imnb57 ca4dc81
Update node/image-generation-with-gemini/src/appwrite.js
imnb57 5b0544c
Update node/image-generation-with-gemini/prettierrc.json
imnb57 481da3a
Update node/image-generation-with-gemini/README.md
imnb57 2c16798
Update node/image-generation-with-gemini/README.md
imnb57 ae06e6a
Update node/image-generation-with-gemini/src/setup.js
imnb57 d6cbaea
Update node/image-generation-with-gemini/src/utils.js
imnb57 6379fc9
Update node/image-generation-with-gemini/src/setup.js
imnb57 3b7c2e3
Update node/image-generation-with-gemini/README.md
imnb57 930fe53
Update node/image-generation-with-gemini/prettierrc.json
imnb57 c27da9d
some fixes
imnb57 a2c8341
fixes
imnb57 04dc389
conflict markers removed
imnb57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| lerna-debug.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # Diagnostic reports (https://nodejs.org/api/report.html) | ||
| report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
|
||
| # Runtime data | ||
| pids | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # Directory for instrumented libs generated by jscoverage/JSCover | ||
| lib-cov | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage | ||
| *.lcov | ||
|
|
||
| # nyc test coverage | ||
| .nyc_output | ||
|
|
||
| # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
| .grunt | ||
|
|
||
| # Bower dependency directory (https://bower.io/) | ||
| bower_components | ||
|
|
||
| # node-waf configuration | ||
| .lock-wscript | ||
|
|
||
| # Compiled binary addons (https://nodejs.org/api/addons.html) | ||
| build/Release | ||
|
|
||
| # Dependency directories | ||
| node_modules/ | ||
| jspm_packages/ | ||
|
|
||
| # Snowpack dependency directory (https://snowpack.dev/) | ||
| web_modules/ | ||
|
|
||
| # TypeScript cache | ||
| *.tsbuildinfo | ||
|
|
||
| # Optional npm cache directory | ||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
| .eslintcache | ||
|
|
||
| # Optional stylelint cache | ||
| .stylelintcache | ||
|
|
||
| # Microbundle cache | ||
| .rpt2_cache/ | ||
| .rts2_cache_cjs/ | ||
| .rts2_cache_es/ | ||
| .rts2_cache_umd/ | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # parcel-bundler cache (https://parceljs.org/) | ||
| .cache | ||
| .parcel-cache | ||
|
|
||
| # Next.js build output | ||
| .next | ||
| out | ||
|
|
||
| # Nuxt.js build / generate output | ||
| .nuxt | ||
| dist | ||
|
|
||
| # Gatsby files | ||
| .cache/ | ||
| # Comment in the public line in if your project uses Gatsby and not Next.js | ||
| # https://nextjs.org/blog/next-9-1#public-directory-support | ||
| # public | ||
|
|
||
| # vuepress build output | ||
| .vuepress/dist | ||
|
|
||
| # vuepress v2.x temp and cache directory | ||
| .temp | ||
| .cache | ||
|
|
||
| # Docusaurus cache and generated files | ||
| .docusaurus | ||
|
|
||
| # Serverless directories | ||
| .serverless/ | ||
|
|
||
| # FuseBox cache | ||
| .fusebox/ | ||
|
|
||
| # DynamoDB Local files | ||
| .dynamodb/ | ||
|
|
||
| # TernJS port file | ||
| .tern-port | ||
|
|
||
| # Stores VSCode versions used for testing VSCode extensions | ||
| .vscode-test | ||
|
|
||
| # yarn v2 | ||
| .yarn/cache | ||
| .yarn/unplugged | ||
| .yarn/build-state.yml | ||
| .yarn/install-state.gz | ||
| .pnp.* | ||
|
|
||
| # Directory used by Appwrite CLI for local development | ||
| .appwrite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "trailingComma": "es5", | ||
| "tabWidth": 2, | ||
| "semi": true, | ||
| "singleQuote": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # ⚡ Image Generation with Gemini (Node) | ||
|
|
||
| Generate images using Google's Gemini API, save them locally, and automatically upload them to an Appwrite Storage bucket. | ||
|
|
||
| ## 🧰 Usage | ||
|
|
||
| ### CLI | ||
|
|
||
| - Generate and upload to Appwrite Storage | ||
|
|
||
| ```powershell | ||
| node src/main.js "A cat running inside a stadium" | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ### Bucket setup helper (optional) | ||
|
|
||
| Ensures the bucket exists (creates it if missing): | ||
|
|
||
| ```powershell | ||
| node src/setup.js | ||
| ``` | ||
| Or the upload function in utils.js does this itself. | ||
|
|
||
| Images are written to `./output` as `gemini-image-<n>.png`. | ||
|
|
||
| ## ⚙️ Configuration | ||
|
|
||
| | Setting | Value | | ||
| | ----------------- | ---------------------------- | | ||
| | Runtime | Node (>=18) | | ||
| | Entrypoint | `src/main.js` | | ||
| | Output folder | `output/` | | ||
| | Upload provider | Appwrite Storage | | ||
| | Bucket (default) | `Generated_Images` | | ||
|
|
||
| > Note: If you plan to run this as an Appwrite Function, set Entrypoint to `src/main.js` and ensure the environment variables below are configured in Appwrite as well. | ||
|
|
||
| ## 🔒 Environment Variables | ||
|
|
||
| Set these in a local `.env` file (or inject in your platform): | ||
|
|
||
| | Variable | Required | Sample Value | Notes | | ||
| | --------------------------------- | -------- | -------------------------------------------- | ---------------------------------------------------------------- | | ||
| | `GEMINI_API_KEY` | Yes | `AIza...` | Google Gemini API key | | ||
| | `GEMINI_MODEL` | No | `gemini-2.0-flash-preview-image-generation` | Defaults to the value shown | | ||
|
|
||
| | `APPWRITE_FUNCTION_API_ENDPOINT` | Yes\* | `https://cloud.appwrite.io/v1` | Appwrite endpoint | | ||
| | `APPWRITE_FUNCTION_PROJECT_ID` | Yes* | `YOUR_PROJECT_ID` | Appwrite project ID | | ||
| | `APPWRITE_FUNCTION_API_KEY` | Yes* | `YOUR_API_KEY` | Appwrite API key with Storage permissions | | ||
| | `APPWRITE_BUCKET_ID` | No | `Generated_Images` | Bucket ID used/created | | ||
|
|
||
| \* Required only when uploading to Appwrite. | ||
|
|
||
| Example `.env` (placeholder values): | ||
|
|
||
| ```dotenv | ||
| GEMINI_API_KEY=YOUR_GEMINI_API_KEY | ||
| GEMINI_MODEL=gemini-2.0-flash-preview-image-generation | ||
|
|
||
|
|
||
| # Appwrite creds (needed when uploading) | ||
| APPWRITE_FUNCTION_API_ENDPOINT=https://cloud.appwrite.io/v1 | ||
| APPWRITE_FUNCTION_PROJECT_ID=YOUR_PROJECT_ID | ||
| APPWRITE_FUNCTION_API_KEY=YOUR_API_KEY | ||
| APPWRITE_BUCKET_ID=Generated_Images | ||
| ``` | ||
|
|
||
|
|
||
| ## ✅ Expected output | ||
|
|
||
| On success, you'll see logs like: | ||
|
|
||
| ```text | ||
| Image saved as D:\...\output\gemini-image-10.png | ||
| ✓ Image created at: D:\...\output\gemini-image-10.png | ||
| 📤 Uploading to Appwrite... | ||
| ✓ Image uploaded to Appwrite with file ID: <FILE_ID> | ||
| ✓ Upload complete! File ID: <FILE_ID> | ||
| ``` | ||
|
|
||
|
|
||
| ## 🧯 Troubleshooting | ||
|
|
||
|
|
||
| - "Cannot read properties of undefined (reading 'size')" | ||
| - Run `npm install` to ensure dependencies are present | ||
|
|
||
| - Use Node 18+ (the SDK relies on `fetch`, `File`, etc.) | ||
|
|
||
| - 401 / 403 errors when uploading | ||
| - Check `APPWRITE_FUNCTION_API_KEY` and `APPWRITE_FUNCTION_PROJECT_ID` | ||
| - Ensure the API key has Storage permissions | ||
|
|
||
|
|
||
| ## 📦 Install | ||
|
|
||
| ```powershell | ||
| npm install | ||
| ``` | ||
|
|
||
| Optionally, format code: | ||
|
|
||
| ```powershell | ||
| npm run format | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| declare global { | ||
| namespace NodeJS { | ||
| interface ProcessEnv { | ||
| // Google Gemini | ||
| GEMINI_API_KEY: string; | ||
| GEMINI_MODEL?: string; | ||
|
|
||
| // Appwrite | ||
| APPWRITE_FUNCTION_API_ENDPOINT?: string; | ||
| APPWRITE_FUNCTION_PROJECT_ID?: string; | ||
| APPWRITE_FUNCTION_API_KEY?: string; | ||
| APPWRITE_BUCKET_ID?: string; | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| export {}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.