Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +71 -0
src/streamlit_app.py
CHANGED
@@ -16,6 +16,77 @@ st.set_page_config(page_title="Biosignal Chatbot", page_icon="🩺", layout="cen
|
|
16 |
st.title("🩺 Biosignal Diagnostic Chatbot")
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
MODELS = {
|
20 |
"ECG": load_mitbih_model(),
|
21 |
"PCG": load_pcg_model(),
|
|
|
16 |
st.title("🩺 Biosignal Diagnostic Chatbot")
|
17 |
|
18 |
|
19 |
+
st.components.v1.html("""
|
20 |
+
<script>
|
21 |
+
// Force file uploader refresh and improve functionality
|
22 |
+
function refreshUploaders() {
|
23 |
+
// Find all file upload areas
|
24 |
+
const uploaders = document.querySelectorAll('[data-testid="stFileUploader"]');
|
25 |
+
|
26 |
+
uploaders.forEach((uploader, index) => {
|
27 |
+
// Add visual feedback
|
28 |
+
const dropzone = uploader.querySelector('[data-testid="stFileUploadDropzone"]');
|
29 |
+
if (dropzone) {
|
30 |
+
dropzone.style.border = '2px dashed #ff6b6b';
|
31 |
+
dropzone.style.backgroundColor = '#f8f9fa';
|
32 |
+
dropzone.style.transition = 'all 0.3s ease';
|
33 |
+
|
34 |
+
// Add hover effects
|
35 |
+
dropzone.addEventListener('dragover', function(e) {
|
36 |
+
e.preventDefault();
|
37 |
+
this.style.backgroundColor = '#e3f2fd';
|
38 |
+
this.style.border = '2px dashed #2196f3';
|
39 |
+
});
|
40 |
+
|
41 |
+
dropzone.addEventListener('dragleave', function(e) {
|
42 |
+
this.style.backgroundColor = '#f8f9fa';
|
43 |
+
this.style.border = '2px dashed #ff6b6b';
|
44 |
+
});
|
45 |
+
|
46 |
+
// Force refresh on file change
|
47 |
+
const input = uploader.querySelector('input[type="file"]');
|
48 |
+
if (input) {
|
49 |
+
input.addEventListener('change', function(e) {
|
50 |
+
console.log('File selected:', e.target.files[0]);
|
51 |
+
// Force a small delay then trigger Streamlit rerun
|
52 |
+
setTimeout(() => {
|
53 |
+
if (window.streamlit) {
|
54 |
+
window.streamlit.setComponentValue(Date.now());
|
55 |
+
}
|
56 |
+
// Alternative: trigger a click on a hidden button
|
57 |
+
const refreshBtn = document.querySelector('[data-testid="baseButton-secondary"]');
|
58 |
+
if (refreshBtn && refreshBtn.textContent.includes('Refresh')) {
|
59 |
+
refreshBtn.click();
|
60 |
+
}
|
61 |
+
}, 100);
|
62 |
+
});
|
63 |
+
}
|
64 |
+
}
|
65 |
+
});
|
66 |
+
}
|
67 |
+
|
68 |
+
// Run on page load and periodically
|
69 |
+
document.addEventListener('DOMContentLoaded', refreshUploaders);
|
70 |
+
setTimeout(refreshUploaders, 1000);
|
71 |
+
setTimeout(refreshUploaders, 3000);
|
72 |
+
|
73 |
+
// Monitor for new content (when tabs are switched)
|
74 |
+
const observer = new MutationObserver(function(mutations) {
|
75 |
+
mutations.forEach(function(mutation) {
|
76 |
+
if (mutation.addedNodes.length > 0) {
|
77 |
+
setTimeout(refreshUploaders, 500);
|
78 |
+
}
|
79 |
+
});
|
80 |
+
});
|
81 |
+
|
82 |
+
observer.observe(document.body, {
|
83 |
+
childList: true,
|
84 |
+
subtree: true
|
85 |
+
});
|
86 |
+
</script>
|
87 |
+
""", height=0)
|
88 |
+
|
89 |
+
|
90 |
MODELS = {
|
91 |
"ECG": load_mitbih_model(),
|
92 |
"PCG": load_pcg_model(),
|