Skip to main content

Gemini Coder

PyPI version Python Versions License: MIT Downloads GitHub stars GitHub issues

A Python tool that uses Google's Gemini API to generate animated GIFs from text prompts.

dancing_robot_cyberpunk animation_6b77c2c1-8e37-4775-af39-a45fecd4c046 butterfly_animation

🙏 Inspired by @Miyamura80's gist

English | 中文

Features

  • Generate animated GIFs using Google's Gemini 2.0 Flash model
  • Improved GIF generation with imageio for better compatibility and reliability
  • Customize animation subject, style, and frame rate
  • Automatic retry logic to ensure multiple frames are generated
  • Simple command-line interface for quick and easy use
  • Support for storing API key in .env file for convenience
  • Progress bars for better user experience
  • Programmatic API for integration into other projects

Documentation

Comprehensive documentation is available to help you understand and extend the project:

  • Architecture Documentation - Detailed overview of the system design, component relationships, and data flow
  • Release Guide - Instructions for releasing new versions of the package
  • Changelog - History of changes and version updates
    • Latest (0.1.2): Improved GIF generation with imageio for better compatibility

Architecture Overview

System Overview

High-level system overview showing the main components and their interactions.

Quick Start

# Install the package
pip install gemini-coder

# Set your API key (one-time setup)
echo "GEMINI_API_KEY=your_api_key_here" > .env

# Generate a GIF with default settings (dancing cat in pixel art style)
gemini-coder

# Generate a GIF with custom subject and style
gemini-coder --subject "a dancing robot" --style "in a neon cyberpunk style"

Requirements

  • Python 3.10+
  • Google Gemini API key

Installation

# Install directly from PyPI
pip install gemini-coder

System Requirements

API Key Setup

You can provide your Gemini API key in several ways:

Create a file named .env in your current directory with the following content:

GEMINI_API_KEY=your_api_key_here

The script will automatically load the API key from this file.

Using Environment Variables

# Set your Gemini API key as an environment variable
export GEMINI_API_KEY="your_api_key_here"

Using Command-line Arguments

# Provide the API key directly as a command-line argument
gemini-coder --api-key "your_api_key_here" --subject "your subject"

Command-line Usage

The command-line interface is the easiest way to use Gemini Coder:

# Generate a GIF with default settings (dancing cat in pixel art style)
gemini-coder

# Generate a GIF with custom subject and style
gemini-coder --subject "a dancing robot" --style "in a neon cyberpunk style"

# Save to a specific output file
gemini-coder --subject "a butterfly emerging from a cocoon" --output butterfly_animation.gif

# Enable verbose output for more detailed logs
gemini-coder --verbose

# Disable automatic preview of the generated GIF
gemini-coder --no-preview

Command-line Options

gemini-coder --help

Available options:

  • --api-key: Google Gemini API key (can also be set via GEMINI_API_KEY environment variable)
  • --subject: Subject of the animation (default: "A cute dancing cat")
  • --style: Style of the animation (default: "in a 8-bit pixel art style")
  • --template: Template for the prompt (default: "Create an animation by generating multiple frames, showing")
  • --framerate: Frames per second for the output GIF (default: 2)
  • --output: Output file path (default: animation_.gif)
  • --max-retries: Maximum number of retries for generating frames (default: 3)
  • --model: Gemini model to use (default: "models/gemini-2.0-flash-exp")
  • --log-file: Path to the log file (default: gemini_coder_generator.log)
  • --verbose: Enable verbose output
  • --no-preview: Disable automatic preview of the generated GIF

Examples

# Generate a blooming flower animation
gemini-coder --subject "a seed growing into a plant and then blooming into a flower" --style "in a watercolor style"

# Create a rocket launch animation with custom frame rate
gemini-coder --subject "a rocket launching into space" --style "in a retro sci-fi style" --framerate 3

# Save to a specific output file
gemini-coder --subject "a butterfly emerging from a cocoon" --output butterfly_animation.gif

Programmatic Usage

You can also use the package programmatically in your own Python code:

import os
from dotenv import load_dotenv
from gemini_coder.core.main import generate_animation

# Load API key from .env file
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")

# Generate the animation
result = generate_animation(
    api_key=api_key,
    subject="a butterfly emerging from a cocoon",
    style="in a watercolor painting style",
    output_path="butterfly_animation.gif",
    framerate=2,
    verbose=True
)

if result:
    print(f"Animation successfully generated at {result}")

See the examples/programmatic_usage.py file for a complete example.

Troubleshooting

  • If you encounter issues with the Gemini API, check your API key and ensure you have access to the Gemini 2.0 Flash model.
  • For any other issues, check the log file (gemini_coder_generator.log) for detailed error messages.
  • Enable verbose output with --verbose for more detailed logs.

License

This project is open source and available under the MIT License.


Gemini Coder

PyPI version Python Versions License: MIT Downloads GitHub stars GitHub issues

一个使用 Google Gemini API 从文本提示生成动画 GIF 的 Python 工具。

🙏 灵感来源于 @Miyamura80 的 gist

English | 中文

功能特点

  • 使用 Google Gemini 2.0 Flash 模型生成动画 GIF
  • 改进的 GIF 生成与 imageio 更好的兼容性和可靠性
  • 自定义动画主题、风格和帧率
  • 自动重试逻辑确保生成多个帧
  • 简单的命令行界面,使用快速方便
  • 支持在 .env 文件中存储 API 密钥,使用更便捷
  • 进度条提供更好的用户体验
  • 提供编程 API,可集成到其他项目中

文档

我们提供了全面的文档,帮助您理解和扩展项目:

  • 架构文档 - 系统设计、组件关系和数据流的详细概述
  • 发布指南 - 发布包新版本的说明
  • 更新日志 - 变更历史和版本更新记录
    • 最新 (0.1.2): 改进的 GIF 生成与 imageio 更好的兼容性和可靠性

架构概览

系统概览

高级系统概览,展示了主要组件及其交互。

快速开始

# 安装包
pip install gemini-coder

# 设置 API 密钥(一次性设置)
echo "GEMINI_API_KEY=你的_API_密钥" > .env

# 使用默认设置生成 GIF(像素风格的跳舞猫)
gemini-coder

# 使用自定义主题和风格生成 GIF
gemini-coder --subject "一个跳舞的机器人" --style "霓虹赛博朋克风格"

系统要求

  • Python 3.10+
  • Google Gemini API 密钥

安装

使用 pip 安装(推荐)

# 直接从 PyPI 安装
pip install gemini-coder

系统要求

API 密钥设置

你可以通过几种方式提供 Gemini API 密钥:

使用 .env 文件(推荐)

在当前目录创建一个名为 .env 的文件,内容如下:

GEMINI_API_KEY=你的_API_密钥

脚本将自动从此文件加载 API 密钥。

使用环境变量

# 将 Gemini API 密钥设置为环境变量
export GEMINI_API_KEY="你的_API_密钥"

使用命令行参数

# 直接在命令行参数中提供 API 密钥
gemini-coder --api-key "你的_API_密钥" --subject "你的主题"

命令行使用

命令行界面是使用 Gemini Coder 最简单的方式:

# 使用默认设置生成 GIF(像素风格的跳舞猫)
gemini-coder

# 使用自定义主题和风格生成 GIF
gemini-coder --subject "一个跳舞的机器人" --style "霓虹赛博朋克风格"

# 保存到特定的输出文件
gemini-coder --subject "一只蝴蝶从茧中羽化" --output butterfly_animation.gif

# 启用详细输出以获取更多日志信息
gemini-coder --verbose

# 禁用自动预览生成的 GIF
gemini-coder --no-preview

命令行选项

gemini-coder --help

可用选项:

  • --api-key: Google Gemini API 密钥(也可以通过 GEMINI_API_KEY 环境变量设置)
  • --subject: 动画主题(默认:"A cute dancing cat")
  • --style: 动画风格(默认:"in a 8-bit pixel art style")
  • --template: 提示模板(默认:"Create an animation by generating multiple frames, showing")
  • --framerate: 输出 GIF 的帧率(默认:2)
  • --output: 输出文件路径(默认:animation_.gif)
  • --max-retries: 生成帧的最大重试次数(默认:3)
  • --model: 使用的 Gemini 模型(默认:"models/gemini-2.0-flash-exp")
  • --log-file: 日志文件路径(默认:gemini_coder_generator.log)
  • --verbose: 启用详细输出
  • --no-preview: 禁用自动预览生成的 GIF

示例

# 生成一朵开花的动画
gemini-coder --subject "一颗种子长成植物然后开花" --style "水彩风格"

# 创建一个火箭发射动画,使用自定义帧率
gemini-coder --subject "一枚火箭发射到太空" --style "复古科幻风格" --framerate 3

# 保存到特定的输出文件
gemini-coder --subject "一只蝴蝶从茧中羽化" --output butterfly_animation.gif

编程使用

你也可以在自己的 Python 代码中以编程方式使用该包:

import os
from dotenv import load_dotenv
from gemini_coder.core.main import generate_animation

# 从 .env 文件加载 API 密钥
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")

# 生成动画
result = generate_animation(
    api_key=api_key,
    subject="一只蝴蝶从茧中羽化",
    style="水彩画风格",
    output_path="butterfly_animation.gif",
    framerate=2,
    verbose=True
)

if result:
    print(f"动画成功生成于 {result}")

查看 examples/programmatic_usage.py 文件获取完整示例。

故障排除

  • 如果你遇到 Gemini API 问题,请检查你的 API 密钥并确保你有权访问 Gemini 2.0 Flash 模型。
  • 对于任何其他问题,请查看日志文件(gemini_coder_generator.log)获取详细的错误信息。
  • 使用 --verbose 参数启用详细输出,以获取更多调试信息。

License

本项目是开源的,根据 MIT 许可证提供。

Metadata

Release files for gemini-coder 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-coder 0.1.2
File Size Uploaded Provenance
gemini_coder-0.1.2.tar.gz 22.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-coder 0.1.2
File Interpreter ABI Platform
gemini_coder-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 37.6 kB

Release files / gemini_coder-0.1.2.tar.gz

Download URL gemini_coder-0.1.2.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7450c5ef3b3e41d61a2a687dbb9759036421d098e2376a39713af642dd40df42
BLAKE2b-256 checksum
How to use checksums
f9614f43de38c196bbe0e8cd63490e1d5b405a5b57109200c85a94a1ff8b674d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / gemini_coder-0.1.2-py3-none-any.whl

Download URL gemini_coder-0.1.2-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aed22ea473104180b356b5545dd8eaf84b8ddf618dde4c58e7ba1a8e767aaeb8
BLAKE2b-256 checksum
How to use checksums
29f291a7db779aa21fc53f4dda4c9c76d968bd545ad2ef4d453260e5eae8fd8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Security for gemini-coder 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page