-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai_studio_interface.html
223 lines (197 loc) · 7.5 KB
/
ai_studio_interface.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Studio - Web Interface</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
color: #333;
}
.container {
max-width: 1200px;
margin: auto;
padding: 20px;
}
h1 {
text-align: center;
}
.section {
margin: 20px 0;
padding: 20px;
background-color: #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
input, textarea, select {
width: 100%;
padding: 10px;
margin: 10px 0;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>AI Studio</h1>
<!-- API Key Inputs -->
<div class="section">
<h2>API Key Configuration</h2>
<label for="openaiKey">OpenAI API Key</label>
<input type="text" id="openaiKey" placeholder="Enter OpenAI API Key">
<label for="replicateKey">Replicate API Key</label>
<input type="text" id="replicateKey" placeholder="Enter Replicate API Key">
<label for="stabilityKey">Stability AI API Key</label>
<input type="text" id="stabilityKey" placeholder="Enter Stability AI API Key">
<button onclick="saveApiKeys()">Save API Keys</button>
</div>
<!-- Image Generation -->
<div class="section">
<h2>Generate Image</h2>
<label for="imagePrompt">Enter Image Generation Prompt</label>
<textarea id="imagePrompt" rows="3" placeholder="Describe the image you want to generate"></textarea>
<button onclick="generateImage()">Generate Image</button>
<div id="imageResult"></div>
</div>
<!-- 3D Model Generation -->
<div class="section">
<h2>Generate 3D Model</h2>
<label for="uploadImage">Upload Image for 3D Model</label>
<input type="file" id="uploadImage" accept="image/*">
<button onclick="generate3DModel()">Generate 3D Model</button>
<div id="modelResult"></div>
</div>
<!-- Video Generation -->
<div class="section">
<h2>Generate Video</h2>
<label for="uploadImageVideo">Upload Image to Convert to Video</label>
<input type="file" id="uploadImageVideo" accept="image/*">
<button onclick="generateVideo()">Generate Video</button>
<div id="videoResult"></div>
</div>
<!-- Music Generation -->
<div class="section">
<h2>Generate Music</h2>
<label for="musicPrompt">Enter Music Generation Prompt</label>
<textarea id="musicPrompt" rows="3" placeholder="Describe the music you want to generate"></textarea>
<button onclick="generateMusic()">Generate Music</button>
<div id="musicResult"></div>
</div>
</div>
<script>
// Save API Keys to Local Storage (Simple Persistence)
function saveApiKeys() {
const openaiKey = document.getElementById('openaiKey').value;
const replicateKey = document.getElementById('replicateKey').value;
const stabilityKey = document.getElementById('stabilityKey').value;
localStorage.setItem('openaiKey', openaiKey);
localStorage.setItem('replicateKey', replicateKey);
localStorage.setItem('stabilityKey', stabilityKey);
alert('API Keys saved successfully!');
}
// Fetch API Keys from Local Storage
function getApiKeys() {
return {
openai: localStorage.getItem('openaiKey'),
replicate: localStorage.getItem('replicateKey'),
stability: localStorage.getItem('stabilityKey')
};
}
// Image Generation
async function generateImage() {
const apiKeys = getApiKeys();
const prompt = document.getElementById('imagePrompt').value;
if (!apiKeys.replicate) {
alert("Please set your Replicate API key.");
return;
}
// Use Replicate's Stable Image Ultra model for image generation
const url = `https://api.replicate.com/v1/predictions`;
const body = {
version: "stabilityai/stable-image-ultra",
input: { prompt: prompt }
};
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Token ${apiKeys.replicate}`,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
const result = await response.json();
document.getElementById('imageResult').innerHTML = `<img src="${result.output}" alt="Generated Image" style="width:100%"/>`;
}
// 3D Model Generation
async function generate3DModel() {
const apiKeys = getApiKeys();
const imageFile = document.getElementById('uploadImage').files[0];
if (!apiKeys.stability || !imageFile) {
alert("Please upload an image and set your Stability API key.");
return;
}
const formData = new FormData();
formData.append('image', imageFile);
const response = await fetch(`https://api.stability.ai/v1/generation/stable-fast-3d`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${apiKeys.stability}` },
body: formData
});
const result = await response.json();
document.getElementById('modelResult').innerHTML = `<a href="${result.url}" target="_blank">Download 3D Model</a>`;
}
// Video Generation
async function generateVideo() {
const apiKeys = getApiKeys();
const imageFile = document.getElementById('uploadImageVideo').files[0];
if (!apiKeys.replicate || !imageFile) {
alert("Please upload an image and set your Replicate API key.");
return;
}
const formData = new FormData();
formData.append('image', imageFile);
const response = await fetch(`https://api.replicate.com/v1/predictions`, {
method: 'POST',
headers: { 'Authorization': `Token ${apiKeys.replicate}` },
body: formData
});
const result = await response.json();
document.getElementById('videoResult').innerHTML = `<video controls style="width:100%"><source src="${result.output}" type="video/mp4"></video>`;
}
// Music Generation
async function generateMusic() {
const apiKeys = getApiKeys();
const prompt = document.getElementById('musicPrompt').value;
if (!apiKeys.replicate) {
alert("Please set your Replicate API key.");
return;
}
const response = await fetch(`https://api.replicate.com/v1/predictions`, {
method: 'POST',
headers: {
'Authorization': `Token ${apiKeys.replicate}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
version: "facebook/musicgen",
input: { text: prompt }
})
});
const result = await response.json();
document.getElementById('musicResult').innerHTML = `<audio controls><source src="${result.output}" type="audio/mpeg"></audio>`;
}
</script>
</body>
</html>