Repository navigation
Expand file tree
/
Copy pathtest_streamlit.py
More file actions
124 lines (97 loc) · 3.63 KB
/
Copy pathtest_streamlit.py
File metadata and controls
124 lines (97 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
Simple test script to verify Streamlit app components work
"""
import streamlit as st
import numpy as np
import time
from datetime import datetime
def test_basic_functionality():
"""Test basic Streamlit functionality"""
st.title("🧪 UPDRS Streamlit App Test")
st.success("✅ Streamlit is working!")
# Test session state
if 'test_counter' not in st.session_state:
st.session_state.test_counter = 0
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Increment Counter"):
st.session_state.test_counter += 1
st.rerun()
with col2:
st.metric("Counter", st.session_state.test_counter)
with col3:
st.metric("Current Time", datetime.now().strftime("%H:%M:%S"))
# Test data visualization
st.subheader("📊 Test Chart")
# Generate sample data
x = np.linspace(0, 10, 100)
y = np.sin(x) + np.random.normal(0, 0.1, 100)
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, mode='lines', name='Test Data'))
fig.update_layout(title="Sample Distance Over Time", height=300)
st.plotly_chart(fig, use_container_width=True)
# Test file operations
st.subheader("📄 Test PDF Generation")
if st.button("Generate Test PDF"):
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from io import BytesIO
buffer = BytesIO()
c = canvas.Canvas(buffer, pagesize=letter)
c.drawString(100, 750, "UPDRS Test Report")
c.drawString(100, 700, f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
c.drawString(100, 650, f"Counter Value: {st.session_state.test_counter}")
c.save()
st.download_button(
label="Download Test PDF",
data=buffer.getvalue(),
file_name=f"test_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf",
mime="application/pdf"
)
# Test MediaPipe import
st.subheader("🤲 MediaPipe Test")
try:
import mediapipe as mp
st.success("✅ MediaPipe imported successfully!")
# Test MediaPipe hands initialization
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(
static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.7,
min_tracking_confidence=0.5
)
st.success("✅ MediaPipe Hands initialized successfully!")
except ImportError as e:
st.error(f"❌ MediaPipe import failed: {e}")
except Exception as e:
st.error(f"❌ MediaPipe initialization failed: {e}")
# Test OpenCV import
st.subheader("📹 OpenCV Test")
try:
import cv2
st.success("✅ OpenCV imported successfully!")
# Test camera availability
cap = cv2.VideoCapture(0)
if cap.isOpened():
st.success("✅ Camera is available!")
cap.release()
else:
st.warning("⚠️ Camera not available (this is normal in some environments)")
except ImportError as e:
st.error(f"❌ OpenCV import failed: {e}")
except Exception as e:
st.error(f"❌ OpenCV test failed: {e}")
# Instructions
st.subheader("🚀 Next Steps")
st.info("""
If all tests pass, you can run the full UPDRS app with:
```bash
streamlit run updrs_streamlit.py
```
The app will be available at: http://localhost:8501
""")
if __name__ == "__main__":
test_basic_functionality()