-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
74 lines (54 loc) · 1.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>
<title>Document</title>
<style>
pre {
display: block;
font-family: monospace;
white-space: pre;
margin: 1em 0;
}
</style>
</head>
<body>
<h1>Trip Planner</h1><input type="text" id="from" placeholder="Starting point"> <input type="text" id="to" placeholder="Destination"> <input type="text" id="days" placeholder="Number of days"> <button id="generateBtn">Generate</button>
<h3>Generated Content</h3>
<div id="output"></div>
<script type="importmap">
{
"imports": {
"@google/generative-ai": "https://esm.run/@google/generative-ai"
}
}
</script>
<script type="module">
import { GoogleGenerativeAI } from "@google/generative-ai";
// Fetch your API_KEY
const API_KEY = "YOURAPIKEY";
// Access your API key (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(API_KEY);
// ...
async function run() {
console.log('Calling');
const fromDest = document.getElementById("from").value;
const toDest = document.getElementById("to").value;
const days = document.getElementById("days").value;
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest" });
const prompt = `Create a travel itinerary from ${fromDest} to ${toDest} for ${days} days.`;
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
var converter = new showdown.Converter();
document.getElementById("output").innerHTML = converter.makeHtml(text);
}
// run();
document.getElementById("generateBtn").addEventListener("click", run);
// ...
</script>
</body>
</html>