Skip to main content

The python package that returns Response of Google Gemini through Cookies.

Project description

Gemini Icon GeminiKit

GeminiKit is an unofficial Python wrapper developed through reverse-engineering. This tool utilizes cookie values to interact with Google Gemini for testing purposes.


Installation

To install GeminiKit, you can use pip:

pip install -U geminikit

or

pip install git+https://github.com/rekcah-pavi/geminikit

Get Cookie File (chrome-net-export-log)

For a detailed video guide, click here.

1. Close All Tabs

Ensure all tabs are closed in Google Chrome.

2. Access Network Export

  • Open a new tab and navigate to chrome://net-export/.

3. Configure Logging Settings

  • Check the box labeled Include cookies and credentials.
  • Set the Maximum log size to 1 MB.
  • Click the Start logging button.

4. Perform Actions

  • Open a new tab and go to gemini.google.com.
  • Log in to your Gemini account.
  • Send a sample message and wait for Gemini's response.

5. Stop Logging

  • Return to the logging tab and click the Stop logging button.

6. Retrieve Cookies

  • The cookies will be saved in a JSON file.

7. Extract Cookies from File

from geminikit import get_cookies_from_file

with open("chrome-net-export-log.json", 'r') as f:
    cookies = get_cookies_from_file(f.read())

print(cookies)

Usage

Setup Gemini

Sync
from geminikit import get_cookies_from_file
from geminikit import Gemini

with open("chrome-net-export-log.json", 'r') as f:
    cookies = get_cookies_from_file(f.read())

gemini = Gemini(cookies)
Async
from geminikit import get_cookies_from_file
from geminikit import Asynic_Gemini as Gemini

import asyncio
import aiofiles #pip install aiofiles

async def main():
    async with aiofiles.open("chrome-net-export-log.json", mode='r') as f:
        cookies = get_cookies_from_file(f.read())

    gemini = await Gemini.create(cookies)

asyncio.run(main())

Ask a Message

Sync
res = gemini.ask("hello")
print(res['text'])
Async
res = await gemini.ask("hello")
print(res['text'])

Ask continuous message

Sync
user = None
while True:
text = input("Ask: ")
res = gemini.ask(text,user=user)
user = res
print(res['text'])
Async
import asyncio

user = None
while True:
 await asyncio.sleep(0)
 text = input("Ask: ")
 res = await gemini.ask(text,user=user)
 user = res
 print(res['text'])

Text to Voice

Sync
res = gemini.speech("hello")
with open("a.wav", "wb") as f:
  f.write(res)
Async
import aiofiles #pip install aiofiles
res = await gemini.speech("hello")
async with aiofiles.open("a.wav", mode='wb') as f:
        await f.write(res)

Ask with Photo

Sync
with open("cat.jpg", "rb") as f:
  img_link = gemini.upload_image(f.read())

photo = ['cat.jpg', img_link]  # photo name (if not available, use 'none.jpg'), link

res = gemini.ask("What is in this photo?", photo=photo)
print(res['text'])
Async
import aiofiles #pip install aiofiles

async with aiofiles.open("cat.jpg", mode='rb') as f:
        img_data = await f.read()
        img_link = await gemini.upload_image(img_data)

photo = ['cat.jpg', img_link]  # photo name (if not available, use 'none.jpg'), link

res = await gemini.ask("What is in this photo?", photo=photo)
print(res['text'])

Save Response Images

Sync
res = gemini.ask("send me some wallpapers")

print(res['text'])

#Or You can access URLs directly
for url in res['image_urls']:
  img_name  = url.split("/")[-1]
  img_bytes = gemini.get_img_bytes(url)
  with open(img_name, 'wb') as f:
      f.write(img_bytes)
Async
import aiofiles #pip install aiofiles


res = await gemini.ask("send me some wallpapers")

print(res['text'])

#Or You can access URLs directly
for url in res['image_urls']:
    img_name  = url.split("/")[-1]
    img_bytes = await gemini.get_img_bytes(url)
    async with aiofiles.open(img_name, mode='wb') as f:
        await f.write(img_bytes)

Save Generated Images

Sync
res = gemini.ask("Generate an image of a cat holding a rose.")

print(res['text'])

for url in res['generated_image_urls']:
  img_name  = url.split("/")[-1][:10] + ".png"
  img_bytes = gemini.get_img_bytes(url)
  with open(img_name, 'wb') as f:
      f.write(img_bytes)
Async
import aiofiles #pip install aiofiles

res = await gemini.ask("Generate an image of a cat holding a rose.")

print(res['text'])

for url in res['generated_image_urls']:
    img_name  = url.split("/")[-1][:10] + ".png"
    img_bytes = await gemini.get_img_bytes(url)

    async with aiofiles.open(img_name, mode='wb') as f:
        await f.write(img_bytes)

Get Sharable URL

Sync
res = gemini.ask("Hi")
url = gemini.share(res['conversation_id'], res['response_id'], res['choice_id'], res['req_id'], res['fsid'], title="test by me")
print(url)
Async
res = await gemini.ask("Hi")
url = await gemini.share(res['conversation_id'], res['response_id'], res['choice_id'], res['req_id'], res['fsid'], title="test by me")
print(url)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geminikit-1.1.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

geminikit-1.1.5-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file geminikit-1.1.5.tar.gz.

File metadata

  • Download URL: geminikit-1.1.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for geminikit-1.1.5.tar.gz
Algorithm Hash digest
SHA256 98691132c974f4157a92684529d4396ac2e61d6f4ebc6c0e1d307e20af5c7221
MD5 dc6fbb7da7d987075f41df77a9cabc93
BLAKE2b-256 083ecfc9c7009b5216b588f1b87d9969686e78a6c61750ff32fdff290374ab3e

See more details on using hashes here.

File details

Details for the file geminikit-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: geminikit-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for geminikit-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c2460dbfb0a1de12f4a324c8e68aa81526a70370b3b12603c17bf2e72f3462dd
MD5 666f4b3a35ce7d246c5a16094282cc2c
BLAKE2b-256 d2ece31fe01d5fd0bbb5d29f336d655589c9e10b815fd8eeaf0b4b65376c12e7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page