Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0349e3c

Browse files
authored
1 parent f971347 commit 0349e3c

File tree

1 file changed

+200
-0
lines changed
  • gemini-image-json.html

1 file changed

+200
-0
lines changed

gemini-image-json.html

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Render JSON from Gemini Image Generationtitle>
7+
<style>
8+
body {
9+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
10+
margin: 0;
11+
padding: 15px;
12+
background-color: #f4f4f4;
13+
color: #333;
14+
line-height: 1.6;
15+
}
16+
.container {
17+
max-width: 800px;
18+
margin: 20px auto;
19+
background-color: #fff;
20+
padding: 20px;
21+
border-radius: 8px;
22+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
23+
}
24+
h1, h2 {
25+
color: #333;
26+
border-bottom: 1px solid #eee;
27+
padding-bottom: 10px;
28+
}
29+
textarea {
30+
width: 100%;
31+
min-height: 200px;
32+
padding: 10px;
33+
border: 1px solid #ddd;
34+
border-radius: 4px;
35+
box-sizing: border-box;
36+
margin-bottom: 10px;
37+
font-family: monospace;
38+
font-size: 0.9em;
39+
}
40+
button {
41+
background-color: #007bff;
42+
color: white;
43+
padding: 10px 15px;
44+
border: none;
45+
border-radius: 4px;
46+
cursor: pointer;
47+
font-size: 1em;
48+
margin-bottom: 20px;
49+
display: block;
50+
width: 100%;
51+
}
52+
button:hover {
53+
background-color: #0056b3;
54+
}
55+
#output img {
56+
max-width: 100%;
57+
height: auto;
58+
display: block;
59+
margin-top: 10px;
60+
margin-bottom: 10px;
61+
border-radius: 4px;
62+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
63+
}
64+
#output p {
65+
margin-top: 0;
66+
margin-bottom: 1em;
67+
white-space: pre-wrap; /* Preserve line breaks from JSON text */
68+
}
69+
#metadata pre {
70+
background-color: #e9ecef;
71+
padding: 15px;
72+
border-radius: 4px;
73+
overflow-x: auto;
74+
font-size: 0.85em;
75+
white-space: pre-wrap;
76+
word-break: break-all;
77+
}
78+
.error {
79+
color: red;
80+
font-weight: bold;
81+
margin-bottom: 10px;
82+
}
83+
.section-title {
84+
margin-top: 30px;
85+
font-size: 1.2em;
86+
color: #555;
87+
}
88+
style>
89+
head>
90+
<body>
91+
<div class="container">
92+
<h1>Render JSON from Gemini Image Generationh1>
93+
94+
<label for="jsonInput">Paste Gemini JSON here:label>
95+
<textarea id="jsonInput" placeholder="Paste your JSON data here...">textarea>
96+
<button id="processButton">Render JSONbutton>
97+
98+
<div id="errorDisplay" class="error">div>
99+
100+
<div id="output">
101+
102+
div>
103+
104+
<div id="metadata">
105+
106+
div>
107+
div>
108+
109+
<script>
110+
document.getElementById('processButton').addEventListener('click', () => {
111+
const jsonString = document.getElementById('jsonInput').value;
112+
const outputDiv = document.getElementById('output');
113+
const metadataDiv = document.getElementById('metadata');
114+
const errorDiv = document.getElementById('errorDisplay');
115+
116+
// Clear previous output and errors
117+
outputDiv.innerHTML = '';
118+
metadataDiv.innerHTML = '';
119+
errorDiv.textContent = '';
120+
121+
if (!jsonString.trim()) {
122+
errorDiv.textContent = 'Please paste some JSON data.';
123+
return;
124+
}
125+
126+
let jsonData;
127+
try {
128+
jsonData = JSON.parse(jsonString);
129+
} catch (e) {
130+
errorDiv.textContent = `Error parsing JSON: ${e.message}`;
131+
return;
132+
}
133+
134+
// Render content from candidates
135+
if (jsonData.candidates && Array.isArray(jsonData.candidates)) {
136+
const candidatesTitle = document.createElement('h2');
137+
candidatesTitle.textContent = 'Rendered Content';
138+
candidatesTitle.classList.add('section-title');
139+
outputDiv.appendChild(candidatesTitle);
140+
141+
jsonData.candidates.forEach((candidate, index) => {
142+
if (candidate.content && candidate.content.parts && Array.isArray(candidate.content.parts)) {
143+
const candidateHeader = document.createElement('h3');
144+
candidateHeader.textContent = `Candidate ${index + 1}`;
145+
candidateHeader.style.fontSize = '1.1em';
146+
candidateHeader.style.marginTop = '20px';
147+
candidateHeader.style.color = '#444';
148+
outputDiv.appendChild(candidateHeader);
149+
150+
candidate.content.parts.forEach(part => {
151+
if (part.text) {
152+
const p = document.createElement('p');
153+
p.textContent = part.text;
154+
outputDiv.appendChild(p);
155+
} else if (part.inlineData && part.inlineData.mimeType && part.inlineData.mimeType.startsWith('image/')) {
156+
const img = document.createElement('img');
157+
img.src = `data:${part.inlineData.mimeType};base64,${part.inlineData.data}`;
158+
img.alt = 'Rendered Image';
159+
outputDiv.appendChild(img);
160+
}
161+
});
162+
}
163+
});
164+
} else {
165+
console.warn("No 'candidates' array found or it's not an array.");
166+
}
167+
168+
// Render usage metadata
169+
if (jsonData.usageMetadata) {
170+
const metadataTitle = document.createElement('h2');
171+
metadataTitle.textContent = 'Usage Metadata';
172+
metadataTitle.classList.add('section-title');
173+
metadataDiv.appendChild(metadataTitle);
174+
175+
const pre = document.createElement('pre');
176+
pre.textContent = JSON.stringify(jsonData.usageMetadata, null, 2); // Pretty print
177+
metadataDiv.appendChild(pre);
178+
} else {
179+
console.warn("No 'usageMetadata' object found.");
180+
}
181+
182+
// Render modelVersion if present
183+
if (jsonData.modelVersion) {
184+
const modelVersionTitle = document.createElement('h2');
185+
modelVersionTitle.textContent = 'Model Version';
186+
modelVersionTitle.classList.add('section-title');
187+
metadataDiv.appendChild(modelVersionTitle); // Appending to metadataDiv for consistency
188+
189+
const p = document.createElement('p');
190+
p.textContent = jsonData.modelVersion;
191+
p.style.backgroundColor = '#e9ecef';
192+
p.style.padding = '10px';
193+
p.style.borderRadius = '4px';
194+
p.style.fontFamily = 'monospace';
195+
metadataDiv.appendChild(p);
196+
}
197+
});
198+
script>
199+
body>
200+
html>

0 commit comments

Comments
(0)