Spaces:
Running
Running
Juno360219
commited on
Commit
•
a411966
1
Parent(s):
fbdd413
Add 3 files
Browse files- index.html +1 -19
- main.js +52 -0
- style.css +8 -28
index.html
CHANGED
@@ -1,19 +1 @@
|
|
1 |
-
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8" />
|
5 |
-
<meta name="viewport" content="width=device-width" />
|
6 |
-
<title>My static Space</title>
|
7 |
-
<link rel="stylesheet" href="style.css" />
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<div class="card">
|
11 |
-
<h1>Welcome to your static Space!</h1>
|
12 |
-
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
13 |
-
<p>
|
14 |
-
Also don't forget to check the
|
15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
16 |
-
</p>
|
17 |
-
</div>
|
18 |
-
</body>
|
19 |
-
</html>
|
|
|
1 |
+
<html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Animated Image Generation</title></head><body><nav></nav><main id="main"><canvas id="stage"></canvas></main></body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.js
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useState, useEffect } from 'alpinejs'
|
2 |
+
import { Tone } from 'three'
|
3 |
+
|
4 |
+
function main() {
|
5 |
+
const [imageUrl, setImageUrl] = useState('')
|
6 |
+
const scene = new THREE.Scene()
|
7 |
+
const camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 0.1, 1000)
|
8 |
+
const renderer = new THREE.WebGLRenderer()
|
9 |
+
const geometry = new THREE.BoxGeometry(1, 1, 1)
|
10 |
+
const material = new THREE.MeshBasicMaterial({ color: 0xFFFFFF })
|
11 |
+
const cube = new THREE.Mesh(geometry, material)
|
12 |
+
scene.add(cube)
|
13 |
+
renderer.setSize(window.innerWidth, window.innerHeight)
|
14 |
+
document.body.appendChild(renderer.domElement)
|
15 |
+
const animate = () => {
|
16 |
+
requestAnimationFrame(animate)
|
17 |
+
cube.rotation.x += 0.01
|
18 |
+
cube.rotation.y += 0.02
|
19 |
+
renderer.render(scene, camera)
|
20 |
+
}
|
21 |
+
animate()
|
22 |
+
}
|
23 |
+
|
24 |
+
function generateImage() {
|
25 |
+
const url = new URL('http://example.com/blob/')
|
26 |
+
url.pathname = '/api/image'
|
27 |
+
const body = new Blob([imageUrl])
|
28 |
+
const request = new Request(url, {
|
29 |
+
method: 'POST',
|
30 |
+
headers: {
|
31 |
+
'Content-Type': 'image/jpeg',
|
32 |
+
},
|
33 |
+
body,
|
34 |
+
})
|
35 |
+
return fetch(request)
|
36 |
+
.then((response) => {
|
37 |
+
if (!response.ok) {
|
38 |
+
throw new Error(`${response.status} ${response.statusText}`)
|
39 |
+
}
|
40 |
+
return response.blob()
|
41 |
+
})
|
42 |
+
.then((blob) => {
|
43 |
+
const image = document.createElement('img')
|
44 |
+
image.src = window.URL.createObjectURL(blob)
|
45 |
+
document.body.appendChild(image)
|
46 |
+
})
|
47 |
+
}
|
48 |
+
|
49 |
+
document.addEventListener('DOMContentLoaded', () => {
|
50 |
+
main()
|
51 |
+
document.getElementById('generate-image').addEventListener('click', generateImage)
|
52 |
+
})
|
style.css
CHANGED
@@ -1,28 +1,8 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
}
|
10 |
-
|
11 |
-
p {
|
12 |
-
color: rgb(107, 114, 128);
|
13 |
-
font-size: 15px;
|
14 |
-
margin-bottom: 10px;
|
15 |
-
margin-top: 5px;
|
16 |
-
}
|
17 |
-
|
18 |
-
.card {
|
19 |
-
max-width: 620px;
|
20 |
-
margin: 0 auto;
|
21 |
-
padding: 16px;
|
22 |
-
border: 1px solid lightgray;
|
23 |
-
border-radius: 16px;
|
24 |
-
}
|
25 |
-
|
26 |
-
.card p:last-child {
|
27 |
-
margin-bottom: 0;
|
28 |
-
}
|
|
|
1 |
+
:root {
|
2 |
+
--background-color: #f1f5f8;
|
3 |
+
--text-default: #181c32;
|
4 |
+
--text-input: #181c32;
|
5 |
+
--button-hover: #1a5a96;
|
6 |
+
--button-active: #123c6b;
|
7 |
+
--button-disable: #87cefa;
|
8 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|