Chatbot_using_Gemini/chatbot.html
Ameya Joshi 526c779105 Upload files to "/"
Html file with free API key included
2025-07-28 19:28:00 +05:30

55 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gemini API Test (Insecure - FOR LOCAL DEV ONLY)</title>
<script type="module">
// WARNING: This approach is INSECURE for production.
// Your API key will be visible to anyone viewing your page source.
const GEMINI_API_KEY = "AIzaSyDJs3ym-w4UnZS3dRrHziybHwes5ORV1Ko"; // <<<--- your actual API Key
// **CORRECTED IMPORT STATEMENT for default export:**
import GoogleGenerativeAI from "https://cdn.jsdelivr.net/npm/@google/generative-ai@latest/dist/index.js";
async function runGemini() {
if (!GEMINI_API_KEY || GEMINI_API_KEY === "AIzaSyDJs3ym-w4UnZS3dRrHziybHwes5ORV1Ko") {
console.error(" 'AIzaSyDJs3ym-w4UnZS3dRrHziybHwes5ORV1Ko'==>your actual Gemini API key.");
document.getElementById('output').innerText = "ERROR: API Key missing or not set. See console.";
return;
}
// Initialize the Generative AI client
const genAI = new GoogleGenerativeAI(GEMINI_API_KEY);
// Choose the model (e.g., "gemini-pro" for text-only, "gemini-pro-vision" for multimodal)
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
const prompt = "What is the capital of France?";
try {
// Generate content from the model
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text(); // Extract the text from the response
// Display the result on the page
document.getElementById('output').innerText = "Gemini says: " + text;
console.log("Gemini response:", text);
} catch (error) {
console.error("Error calling Gemini API:", error);
document.getElementById('output').innerText = "Error: " + error.message + ". Check console for details.";
}
}
// Run the function when the page loads
document.addEventListener('DOMContentLoaded', runGemini);
</script>
</head>
<body>
<h1>Gemini API Direct Embedding Test</h1>
<p>This is for local development testing ONLY. Your API key is exposed in the source code.</p>
<div id="output">Loading Gemini response...</div>
</body>
</html>