Update app.py
Browse files
app.py
CHANGED
|
@@ -22,22 +22,25 @@ def generate_code_and_response(prompt):
|
|
| 22 |
f"Want me to tweak this code, explain it, or whip up something else? I’m all cosmic curiosity!"
|
| 23 |
)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
# Wrap response in HTML with JavaScript for typing effect
|
| 26 |
-
html_response =
|
| 27 |
<div id="typing-output" style="font-family: Arial, sans-serif; font-size: 16px; white-space: pre-wrap;"></div>
|
| 28 |
<script>
|
| 29 |
-
const text =
|
| 30 |
let index = 0;
|
| 31 |
const speed = 30; // Typing speed in milliseconds
|
| 32 |
const outputElement = document.getElementById('typing-output');
|
| 33 |
|
| 34 |
-
function typeWriter() {
|
| 35 |
-
if (index < text.length) {
|
| 36 |
outputElement.innerHTML += text.charAt(index);
|
| 37 |
index++;
|
| 38 |
setTimeout(typeWriter, speed);
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
typeWriter();
|
| 42 |
</script>
|
| 43 |
"""
|
|
|
|
| 22 |
f"Want me to tweak this code, explain it, or whip up something else? I’m all cosmic curiosity!"
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# Escape special characters for JavaScript
|
| 26 |
+
escaped_response = response_text.replace("`", "\\`").replace("\n", "\\n")
|
| 27 |
+
|
| 28 |
# Wrap response in HTML with JavaScript for typing effect
|
| 29 |
+
html_response = """
|
| 30 |
<div id="typing-output" style="font-family: Arial, sans-serif; font-size: 16px; white-space: pre-wrap;"></div>
|
| 31 |
<script>
|
| 32 |
+
const text = '""" + escaped_response + """';
|
| 33 |
let index = 0;
|
| 34 |
const speed = 30; // Typing speed in milliseconds
|
| 35 |
const outputElement = document.getElementById('typing-output');
|
| 36 |
|
| 37 |
+
function typeWriter() {
|
| 38 |
+
if (index < text.length) {
|
| 39 |
outputElement.innerHTML += text.charAt(index);
|
| 40 |
index++;
|
| 41 |
setTimeout(typeWriter, speed);
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
typeWriter();
|
| 45 |
</script>
|
| 46 |
"""
|