45 |
46 | );
47 | };
48 |
49 | export default Features;
--------------------------------------------------------------------------------
/src/components/apis/geminiAPI.js:
--------------------------------------------------------------------------------
1 | import { GoogleGenerativeAI } from "@google/generative-ai";
2 |
3 | const genAI = new GoogleGenerativeAI(process.env.REACT_APP_GEMINI_API_KEY);
4 |
5 | export const generateIdeaContent = async (idea) => {
6 | // Define the model outside the try block for broader scope
7 | let model;
8 |
9 | try {
10 | // Initialize the model
11 | model = await genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
12 |
13 | // Enhanced prompt to act as a software engineer
14 | const prompt = `You are a seasoned software engineer. Please provide the only HTML and Tailwind CSS code for the following idea: ${idea}.
15 |
16 | **Important Notes:**
17 | * Code will be formatted in like prettier
18 | * If the question is irrelevant or does not pertain to the provided idea, respond with: "I cannot answer that."
19 | * No explanation will be needed, just code.`;
20 |
21 | const result = await model.generateContent(prompt);
22 | return result.response.text();
23 | } catch (error) {
24 | console.error("Error generating content:", error);
25 |
26 | // If RECITATION error occurs, retry with a slightly modified prompt
27 | if (error.message.includes("RECITATION")) {
28 | console.warn("Retrying with slight prompt variation...");
29 | try {
30 | const result = await model.generateContent(
31 | `${idea} (Describe its unique features)`
32 | );
33 | return result.response.text();
34 | } catch (retryError) {
35 | throw new Error(
36 | "The generated content was flagged. Please try rephrasing your idea or adding more details."
37 | );
38 | }
39 | } else {
40 | throw new Error(
41 | "An error occurred while generating content. Please try again."
42 | );
43 | }
44 | }
45 | };
46 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Gemini Coder
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/IdeaInput.js:
--------------------------------------------------------------------------------
1 | // src/IdeaInput.js
2 | import React, { useState } from "react";
3 | import { generateIdeaContent } from "./components/apis/geminiAPI";
4 | import DOMPurify from "dompurify";
5 | import { marked } from "marked";
6 | import Navbar from "./components/Navbar";
7 | import Footer from "./components/Footer";
8 | import Header from "./components/Header";
9 | import IdeaForm from "./components/IdeaForm";
10 | import GeneratedCode from "./components/GeneratedCode";
11 | import Features from "./components/Features";
12 |
13 | const IdeaInput = () => {
14 | const [idea, setIdea] = useState("");
15 | const [loading, setLoading] = useState(false);
16 | const [error, setError] = useState(null);
17 | const [htmlContent, setHtmlContent] = useState("");
18 |
19 | const handleSubmit = async () => {
20 | const wordCount = idea.trim().split(/\s+/).length;
21 | if (wordCount < 15) {
22 | setError(
23 | "Please provide a more detailed description of your idea (at least 15 words)."
24 | );
25 | return;
26 | }
27 |
28 | setLoading(true);
29 | setError(null);
30 | setHtmlContent("");
31 |
32 | try {
33 | const markdownCode = await generateIdeaContent(idea);
34 | console.log("markdownCode:::::::::::::", markdownCode);
35 | const html = marked(markdownCode);
36 | const cleanHtml = DOMPurify.sanitize(html);
37 | setHtmlContent(cleanHtml);
38 | } catch (err) {
39 | console.error(err);
40 | setError("Failed to generate content. Please try again.");
41 | } finally {
42 | setLoading(false);
43 | }
44 | };
45 |
46 | return (
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 | {htmlContent && }
61 |
62 |
63 |
64 |
65 |
66 |
67 | );
68 | };
69 |
70 | export default IdeaInput;
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GeminiCoder - App Idea Generator
2 |
3 | GeminiCoder is a web application that helps users transform their app ideas into reality by generating HTML and Tailwind CSS code using AI. The application leverages the Google Generative AI model to provide detailed technical specifications based on user input.
4 |
5 | ## Features
6 |
7 | - **AI-Powered Code Generation**: Generate HTML and Tailwind CSS code based on your app idea.
8 |
9 | ## Getting Started
10 |
11 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
12 |
13 | ### Prerequisites
14 |
15 | - Node.js (version 14 or higher)
16 | - npm (Node Package Manager)
17 |
18 | ### Installation
19 |
20 | 1. Clone the repository:
21 |
22 | ```bash
23 | git clone https://github.com/ekramasif/GeminiCoder.git
24 | cd GeminiCoder
25 | ```
26 |
27 | 2. Install the dependencies:
28 |
29 | ```bash
30 | npm install
31 | ```
32 |
33 | 3. Set up your environment variables. Create a `.env` file in the root directory and add your Google Generative AI API key:
34 |
35 | ```plaintext
36 | REACT_APP_GEMINI_API_KEY=your_api_key_here
37 | ```
38 |
39 | ### Obtaining Your Google Generative AI API Key
40 |
41 | To use the Google Generative AI model, you need to obtain an API key. Follow these steps:
42 |
43 | 1. **Create a Google Cloud Project**:
44 | - Go to the [ai.google.dev](https://ai.google.dev/gemini-api/docs/api-key).
45 | - Click on the project drop-down and select or create a new project.
46 |
47 | 2. **Enable the Google Generative AI API**:
48 | - In the Google Cloud Console, navigate to the **API & Services** dashboard.
49 | - Click on **Enable APIs and Services**.
50 | - Search for "Google Generative AI" and enable it for your project.
51 |
52 | 3. **Create Credentials**:
53 | - In the API & Services dashboard, click on **Credentials** in the left sidebar.
54 | - Click on **Create Credentials** and select **API Key**.
55 | - Your new API key will be generated. Copy this key.
56 |
57 | 4. **Add the API Key to Your `.env` File**:
58 | - Open the `.env` file you created in the root directory of your project.
59 | - Replace `your_api_key_here` with the API key you copied.
60 |
61 | ### Running the Application
62 |
63 | In the project directory, you can run:
64 |
65 | #### `npm start`
66 |
67 | Runs the app in development mode.\
68 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
69 |
70 | The page will reload when you make changes.\
71 | You may also see any lint errors in the console.
72 |
73 |
74 | ## Acknowledgments
75 |
76 | - [Google Generative AI](https://cloud.google.com/generative-ai) for providing the AI model.
77 | - [Tailwind CSS](https://tailwindcss.com/) for the utility-first CSS framework.
78 | - [React](https://reactjs.org/) for the JavaScript library for building user interfaces.
79 |
--------------------------------------------------------------------------------
/src/components/Footer.js:
--------------------------------------------------------------------------------
1 | // src/Footer.js
2 | import React from "react";
3 | import { FaGithub } from "react-icons/fa";
4 |
5 | const Footer = () => {
6 | return (
7 |
79 | );
80 | };
81 |
82 | export default Footer;
--------------------------------------------------------------------------------