Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
+
|
| 4 |
+
def audio_visualizer():
|
| 5 |
+
# HTML/JS component for audio visualization
|
| 6 |
+
html_code = """
|
| 7 |
+
<div style="background: #1a1a1a; padding: 20px; border-radius: 10px;">
|
| 8 |
+
<button id="startButton" style="padding: 10px 20px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 20px;">
|
| 9 |
+
π΅ Start
|
| 10 |
+
</button>
|
| 11 |
+
<canvas id="visualizer" style="width: 100%; height: 400px;"></canvas>
|
| 12 |
+
|
| 13 |
+
<script>
|
| 14 |
+
const canvas = document.getElementById('visualizer');
|
| 15 |
+
const ctx = canvas.getContext('2d');
|
| 16 |
+
const startButton = document.getElementById('startButton');
|
| 17 |
+
const emojis = ['π΅', 'πΆ', 'πΈ', 'πΉ', 'πΊ', 'π·', 'π₯', 'π»'];
|
| 18 |
+
let audioContext, analyser, dataArray, source, animationId;
|
| 19 |
+
let isActive = false;
|
| 20 |
+
|
| 21 |
+
function setupCanvas() {
|
| 22 |
+
canvas.width = canvas.offsetWidth;
|
| 23 |
+
canvas.height = canvas.offsetHeight;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
function init() {
|
| 27 |
+
setupCanvas();
|
| 28 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 29 |
+
analyser = audioContext.createAnalyser();
|
| 30 |
+
analyser.fftSize = 256;
|
| 31 |
+
dataArray = new Uint8Array(analyser.frequencyBinCount);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function draw() {
|
| 35 |
+
if (!isActive) return;
|
| 36 |
+
animationId = requestAnimationFrame(draw);
|
| 37 |
+
analyser.getByteFrequencyData(dataArray);
|
| 38 |
+
|
| 39 |
+
ctx.fillStyle = 'rgba(26, 26, 26, 0.2)';
|
| 40 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 41 |
+
|
| 42 |
+
// Draw bars and emojis
|
| 43 |
+
const barWidth = canvas.width / analyser.frequencyBinCount;
|
| 44 |
+
dataArray.forEach((value, i) => {
|
| 45 |
+
const percent = value / 255;
|
| 46 |
+
const h = percent * canvas.height;
|
| 47 |
+
const hue = i / analyser.frequencyBinCount * 360;
|
| 48 |
+
|
| 49 |
+
ctx.fillStyle = `hsl(${hue}, 70%, 50%)`;
|
| 50 |
+
ctx.fillRect(i * barWidth, canvas.height - h, barWidth - 1, h);
|
| 51 |
+
|
| 52 |
+
if (i % 16 === 0) {
|
| 53 |
+
ctx.font = `${20 + percent * 20}px Arial`;
|
| 54 |
+
ctx.fillText(
|
| 55 |
+
emojis[i % emojis.length],
|
| 56 |
+
i * barWidth,
|
| 57 |
+
canvas.height - h - 30
|
| 58 |
+
);
|
| 59 |
+
}
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
async function toggleAudio() {
|
| 64 |
+
if (!isActive) {
|
| 65 |
+
try {
|
| 66 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 67 |
+
source = audioContext.createMediaStreamSource(stream);
|
| 68 |
+
source.connect(analyser);
|
| 69 |
+
isActive = true;
|
| 70 |
+
startButton.textContent = 'π΅ Stop';
|
| 71 |
+
draw();
|
| 72 |
+
} catch (err) {
|
| 73 |
+
console.error('Error:', err);
|
| 74 |
+
startButton.textContent = 'β Error';
|
| 75 |
+
}
|
| 76 |
+
} else {
|
| 77 |
+
source.disconnect();
|
| 78 |
+
cancelAnimationFrame(animationId);
|
| 79 |
+
isActive = false;
|
| 80 |
+
startButton.textContent = 'π΅ Start';
|
| 81 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
window.addEventListener('resize', setupCanvas);
|
| 86 |
+
startButton.addEventListener('click', toggleAudio);
|
| 87 |
+
init();
|
| 88 |
+
</script>
|
| 89 |
+
</div>
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
st.title("π΅ Deep Research Evaluator π")
|
| 93 |
+
st.markdown("### Audio Visualizer with Emojis")
|
| 94 |
+
|
| 95 |
+
# Custom CSS
|
| 96 |
+
st.markdown("""
|
| 97 |
+
<style>
|
| 98 |
+
.stApp {
|
| 99 |
+
background-color: #0e1117;
|
| 100 |
+
color: white;
|
| 101 |
+
}
|
| 102 |
+
</style>
|
| 103 |
+
""", unsafe_allow_html=True)
|
| 104 |
+
|
| 105 |
+
# Render HTML component
|
| 106 |
+
components.html(html_code, height=500)
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
audio_visualizer()
|