Skip to content

Conversation

Giom-V
Copy link
Collaborator

@Giom-V Giom-V commented Aug 28, 2025

…gic_mirror.js` script and that the script contains all the necessary logic for the application to run.

…gic_mirror.js` script and that the script contains all the necessary logic for the application to run.
@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Aug 28, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Giom-V, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request completely refactors the quickstarts-js directory by removing the extensive Get_Started.js example and introducing a new, interactive "Magic Mirror" web application. The new application demonstrates the Gemini API's image generation capabilities, allowing users to capture their webcam feed and transform it into a "princess" image, accompanied by witty, rhyming responses from an AI-powered "magic mirror."

Highlights

  • Replaced comprehensive quickstart: The previous quickstarts-js/Get_Started.js file, which contained a broad range of Gemini API examples, has been removed.
  • Introduced "Magic Mirror" application: A new web-based application is introduced, featuring an index.html for the user interface and magic_mirror.js for its functionality.
  • Webcam integration and image generation: The magic_mirror.js script captures live webcam input, sends it to the Gemini API (gemini-2.5-flash-image-preview model), and displays the AI-generated image transformation.
  • Persona-driven AI interaction: The application utilizes Gemini's system instruction feature to make the "magic mirror" respond in a witty, sassy, and rhyming manner, enhancing user engagement.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Giom-V Giom-V closed this Aug 28, 2025
@Giom-V Giom-V deleted the jules branch August 28, 2025 09:39
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new 'Magic Mirror' web application example, which is a great addition. However, it also removes the comprehensive Get_Started.js quickstart file. This is a significant change that isn't mentioned in the pull request description and will require an update to the quickstarts-js/README.md to avoid broken links and confusion for users.

I've found a critical issue in magic_mirror.js where the API key is accessed using process.env.GEMINI_API_KEY. This is a Node.js environment variable and will not work in a browser, preventing the application from functioning. I've also added comments regarding error handling, safe data access, and coding conventions to improve the robustness and consistency of the new code.

document.body.insertBefore(speech, document.body.firstChild);


const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

process.env.GEMINI_API_KEY is a Node.js feature and is not available in the browser. This will cause a ReferenceError: process is not defined and the application will fail to initialize the GenAI client. For a client-side demo application, a simple approach is to prompt the user to enter their API key.

Suggested change
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const ai = new GoogleGenAI({ apiKey: window.prompt("Please enter your Gemini API Key:") });

Comment on lines +44 to +75
async function edit_camera_image() {
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0, 640, 480);
const dataUrl = canvas.toDataURL('image/png');
const imageData = dataUrl.split(',')[1]; // Get only base64 string

const imagePart = {
inlineData: {
data: imageData,
mimeType: "image/png"
}
};

const response = await ai.models.generateContent({
model: MODEL_ID,
contents: [imagePart, 'Mirror, mirror on the wall, make me a princess after all!'],
config: {
systemInstruction: "You are a magic mirror. You are witty, a bit sassy, and you always speak in rhymes. You are here to make people's dreams come true, but you do it with a bit of flair and humor.",
}
});

for (const part of response.candidates[0].content.parts) {
if (part.text) {
speech.textContent = part.text;
}
if (part.inlineData) {
const base64ImageBytes = part.inlineData.data;
const imageUrl = `data:image/png;base64,${base64ImageBytes}`;
result.src = imageUrl;
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This function lacks error handling for the API call and has unsafe access to the response object. If generateContent fails or returns no candidates (e.g., due to safety filters), the app will either have an unhandled error or throw a TypeError. It's better to wrap the logic in a try...catch block and check for the existence of candidates before processing them. This suggestion refactors the function to be more robust.

async function edit_camera_image() {
    try {
        const context = canvas.getContext('2d');
        context.drawImage(video, 0, 0, 640, 480);
        const dataUrl = canvas.toDataURL('image/png');
        const imageData = dataUrl.split(',')[1]; // Get only base64 string

        const imagePart = {
            inlineData: {
                data: imageData,
                mimeType: "image/png"
            }
        };

        const response = await ai.models.generateContent({
            model: MODEL_ID,
            contents: [imagePart, 'Mirror, mirror on the wall, make me a princess after all!'],
            config: {
                systemInstruction: "You are a magic mirror. You are witty, a bit sassy, and you always speak in rhymes. You are here to make people's dreams come true, but you do it with a bit of flair and humor.",
            }
        });

        const candidate = response?.candidates?.[0];
        if (candidate) {
            for (const part of candidate.content.parts) {
                if (part.text) {
                    speech.textContent = part.text;
                }
                if (part.inlineData) {
                    const base64ImageBytes = part.inlineData.data;
                    const imageUrl = `data:image/png;base64,${base64ImageBytes}`;
                    result.src = imageUrl;
                }
            }
        } else {
            speech.textContent = "The mirror has nothing to show or say... Try again?";
        }
    } catch (err) {
        console.error("Error generating content:", err);
        speech.textContent = "Oops! The magic mirror is a bit shy today. Please try again.";
    }
}

}

// Event listener for the snap button
snap.addEventListener('click', edit_camera_image);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function name edit_camera_image uses snake_case. While the provided style guide is for Python, the common convention for JavaScript is camelCase (editCameraImage). Using camelCase would also make it consistent with the startWebcam function in this file. Remember to update the function definition on line 44 as well.

Suggested change
snap.addEventListener('click', edit_camera_image);
snap.addEventListener('click', editCameraImage);

@Giom-V Giom-V added the AI generated Looks like AI generated content label Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI generated Looks like AI generated content status:awaiting review PR awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant