Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,91 +1,168 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
st.
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
<style>
|
28 |
-
@keyframes move {
|
29 |
-
0% { transform: translateX(0); }
|
30 |
-
50% { transform: translateX(100px); }
|
31 |
-
100% { transform: translateX(0); }
|
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 |
camera.position.z = 5;
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
}
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
</script>
|
85 |
-
|
86 |
-
|
87 |
-
""
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
st.sidebar.info("Use the buttons and sections above to interact with different components of the app.")
|
|
|
1 |
import streamlit as st
|
2 |
+
import base64
|
3 |
+
|
4 |
+
st.set_page_config(layout="wide", page_title="Game Dev and 3D Showcase")
|
5 |
+
|
6 |
+
st.title("Game Development and 3D Content Showcase")
|
7 |
+
|
8 |
+
# HTML5 Game
|
9 |
+
st.header("HTML5 Game")
|
10 |
+
html5_game = """
|
11 |
+
<canvas id="gameCanvas" width="400" height="300"></canvas>
|
12 |
+
<script>
|
13 |
+
const canvas = document.getElementById('gameCanvas');
|
14 |
+
const ctx = canvas.getContext('2d');
|
15 |
+
let x = canvas.width / 2;
|
16 |
+
let y = canvas.height - 30;
|
17 |
+
let dx = 2;
|
18 |
+
let dy = -2;
|
19 |
+
const ballRadius = 10;
|
20 |
+
|
21 |
+
function drawBall() {
|
22 |
+
ctx.beginPath();
|
23 |
+
ctx.arc(x, y, ballRadius, 0, Math.PI * 2);
|
24 |
+
ctx.fillStyle = "#0095DD";
|
25 |
+
ctx.fill();
|
26 |
+
ctx.closePath();
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
+
|
29 |
+
function draw() {
|
30 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
31 |
+
drawBall();
|
32 |
+
|
33 |
+
if (x + dx > canvas.width - ballRadius || x + dx < ballRadius) {
|
34 |
+
dx = -dx;
|
35 |
+
}
|
36 |
+
if (y + dy > canvas.height - ballRadius || y + dy < ballRadius) {
|
37 |
+
dy = -dy;
|
38 |
+
}
|
39 |
+
|
40 |
+
x += dx;
|
41 |
+
y += dy;
|
42 |
+
}
|
43 |
+
|
44 |
+
setInterval(draw, 10);
|
45 |
+
</script>
|
46 |
+
"""
|
47 |
+
st.components.v1.html(html5_game, height=350)
|
48 |
+
|
49 |
+
# Mad Lib Generator
|
50 |
+
st.header("Mad Lib Generator")
|
51 |
+
|
52 |
+
templates = [
|
53 |
+
"The {adjective} {noun} {verb} over the {adjective} {noun}.",
|
54 |
+
"In a {adjective} land, a {noun} and a {noun} went on a {adjective} adventure.",
|
55 |
+
"The {noun} {verb} {adverb} while the {adjective} {noun} watched in amazement."
|
56 |
+
]
|
57 |
+
|
58 |
+
parts_of_speech = {
|
59 |
+
"adjective": ["brave", "mysterious", "colorful", "gigantic", "tiny"],
|
60 |
+
"noun": ["wizard", "dragon", "knight", "castle", "forest"],
|
61 |
+
"verb": ["flew", "danced", "sang", "fought", "explored"],
|
62 |
+
"adverb": ["quickly", "silently", "gracefully", "fiercely", "carefully"]
|
63 |
+
}
|
64 |
+
|
65 |
+
def generate_mad_lib():
|
66 |
+
import random
|
67 |
+
template = random.choice(templates)
|
68 |
+
for part in parts_of_speech:
|
69 |
+
while "{" + part + "}" in template:
|
70 |
+
template = template.replace("{" + part + "}", random.choice(parts_of_speech[part]), 1)
|
71 |
+
return template
|
72 |
+
|
73 |
+
if st.button("Generate Mad Lib"):
|
74 |
+
st.write(generate_mad_lib())
|
75 |
+
|
76 |
+
# A-Frame 3D Scene
|
77 |
+
st.header("A-Frame 3D Scene")
|
78 |
+
aframe_scene = """
|
79 |
+
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
|
80 |
+
<a-scene embedded style="height: 400px;">
|
81 |
+
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
|
82 |
+
<a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
|
83 |
+
<a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
|
84 |
+
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
|
85 |
+
<a-sky color="#ECECEC"></a-sky>
|
86 |
+
</a-scene>
|
87 |
+
"""
|
88 |
+
st.components.v1.html(aframe_scene, height=450)
|
89 |
|
90 |
+
# Three.js 3D Model Viewer
|
91 |
+
st.header("Three.js 3D Model Viewer")
|
92 |
+
threejs_viewer = """
|
93 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
94 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/OBJLoader.js"></script>
|
95 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.js"></script>
|
96 |
+
<div id="model-container" style="width: 100%; height: 400px;"></div>
|
97 |
+
<script>
|
98 |
+
let scene, camera, renderer, model;
|
99 |
+
|
100 |
+
function init() {
|
101 |
+
scene = new THREE.Scene();
|
102 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
103 |
+
renderer = new THREE.WebGLRenderer();
|
104 |
+
renderer.setSize(window.innerWidth, 400);
|
105 |
+
document.getElementById('model-container').appendChild(renderer.domElement);
|
106 |
+
|
107 |
+
const light = new THREE.PointLight(0xffffff, 1, 100);
|
108 |
+
light.position.set(0, 0, 10);
|
109 |
+
scene.add(light);
|
110 |
|
111 |
camera.position.z = 5;
|
112 |
+
animate();
|
113 |
+
}
|
114 |
|
115 |
+
function animate() {
|
116 |
+
requestAnimationFrame(animate);
|
117 |
+
if (model) {
|
118 |
+
model.rotation.x += 0.01;
|
119 |
+
model.rotation.y += 0.01;
|
120 |
}
|
121 |
+
renderer.render(scene, camera);
|
122 |
+
}
|
123 |
+
|
124 |
+
function loadModel(url, fileType) {
|
125 |
+
let loader;
|
126 |
+
if (fileType === 'obj') {
|
127 |
+
loader = new THREE.OBJLoader();
|
128 |
+
} else if (fileType === 'glb') {
|
129 |
+
loader = new THREE.GLTFLoader();
|
130 |
+
}
|
131 |
+
|
132 |
+
loader.load(url, function(object) {
|
133 |
+
if (model) {
|
134 |
+
scene.remove(model);
|
135 |
+
}
|
136 |
+
model = fileType === 'obj' ? object : object.scene;
|
137 |
+
scene.add(model);
|
138 |
+
});
|
139 |
+
}
|
140 |
+
init();
|
141 |
+
</script>
|
142 |
+
"""
|
143 |
+
st.components.v1.html(threejs_viewer, height=450)
|
144 |
+
|
145 |
+
# File uploader for 3D models
|
146 |
+
uploaded_file = st.file_uploader("Upload a 3D model (OBJ or GLB)", type=['obj', 'glb'])
|
147 |
+
|
148 |
+
if uploaded_file is not None:
|
149 |
+
# Get the file extension
|
150 |
+
file_extension = uploaded_file.name.split('.')[-1].lower()
|
151 |
+
|
152 |
+
# Encode the file
|
153 |
+
encoded_file = base64.b64encode(uploaded_file.read()).decode()
|
154 |
+
|
155 |
+
# Create a data URL
|
156 |
+
data_url = f"data:application/octet-stream;base64,{encoded_file}"
|
157 |
+
|
158 |
+
# JavaScript to load the model
|
159 |
+
load_model_js = f"""
|
160 |
+
<script>
|
161 |
+
loadModel("{data_url}", "{file_extension}");
|
162 |
</script>
|
163 |
+
"""
|
164 |
+
st.components.v1.html(load_model_js, height=0)
|
165 |
+
st.success(f"Loaded {uploaded_file.name}")
|
166 |
|
167 |
+
st.sidebar.title("Navigation")
|
168 |
+
st.sidebar.info("Use the sections above to interact with different components of the app.")
|
|