Spaces:
Runtime error
Runtime error
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# API processing function
|
5 |
+
def analyze_blood_test(file, username, password, language='English'):
|
6 |
+
url = 'https://app.aibloodtestinterpret.com/api/analyze'
|
7 |
+
files = {'file': (file.name, file, 'multipart/form-data')}
|
8 |
+
data = {'username': username, 'password': password, 'language': language}
|
9 |
+
response = requests.post(url, files=files, data=data)
|
10 |
+
|
11 |
+
return response
|
12 |
+
|
13 |
+
# Main function for the Streamlit app
|
14 |
+
def main():
|
15 |
+
# Custom CSS styling for the app
|
16 |
+
st.markdown(
|
17 |
+
"""
|
18 |
+
<style>
|
19 |
+
body {
|
20 |
+
font-family: Arial, sans-serif;
|
21 |
+
background-color: #f8f9fa;
|
22 |
+
color: #343a40;
|
23 |
+
}
|
24 |
+
.main {
|
25 |
+
background-color: #ffffff;
|
26 |
+
padding: 2rem;
|
27 |
+
border-radius: 0.5rem;
|
28 |
+
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
|
29 |
+
}
|
30 |
+
h1 {
|
31 |
+
color: #007bff;
|
32 |
+
font-size: 2.5rem;
|
33 |
+
text-align: center;
|
34 |
+
margin-bottom: 2rem;
|
35 |
+
}
|
36 |
+
h2, h3, h4 {
|
37 |
+
color: #0056b3;
|
38 |
+
}
|
39 |
+
.sidebar .sidebar-content {
|
40 |
+
background-color: #e9ecef;
|
41 |
+
padding: 2rem;
|
42 |
+
border-radius: 0.5rem;
|
43 |
+
}
|
44 |
+
.stButton>button {
|
45 |
+
background-color: #007bff;
|
46 |
+
color: white;
|
47 |
+
border-radius: 0.25rem;
|
48 |
+
padding: 0.75rem 1.5rem;
|
49 |
+
font-size: 1rem;
|
50 |
+
cursor: pointer;
|
51 |
+
}
|
52 |
+
.stButton>button:hover {
|
53 |
+
background-color: #0056b3;
|
54 |
+
}
|
55 |
+
.stDownloadButton>button {
|
56 |
+
background-color: #28a745;
|
57 |
+
color: white;
|
58 |
+
border-radius: 0.25rem;
|
59 |
+
padding: 0.75rem 1.5rem;
|
60 |
+
font-size: 1rem;
|
61 |
+
cursor: pointer;
|
62 |
+
}
|
63 |
+
.stDownloadButton>button:hover {
|
64 |
+
background-color: #218838;
|
65 |
+
}
|
66 |
+
</style>
|
67 |
+
""",
|
68 |
+
unsafe_allow_html=True
|
69 |
+
)
|
70 |
+
|
71 |
+
# App main content
|
72 |
+
st.title('AI Blood Test Interpretation')
|
73 |
+
|
74 |
+
st.sidebar.title('About')
|
75 |
+
st.sidebar.info('''\
|
76 |
+
### Free Trial Available
|
77 |
+
Take advantage of our limited-time free trial for all humanity.
|
78 |
+
''')
|
79 |
+
st.sidebar.info('''\
|
80 |
+
### Product Release
|
81 |
+
After 1.5 years of diligent effort, the AI Blood Test Interpretation tool is now officially launched.
|
82 |
+
''')
|
83 |
+
|
84 |
+
st.write('Welcome to the AI-driven Blood Test Interpreter. Upload your blood test file and get a detailed analysis within seconds.')
|
85 |
+
|
86 |
+
uploaded_file = st.file_uploader('Upload your blood test image or PDF', type=['jpg', 'jpeg', 'png', 'pdf'])
|
87 |
+
username = st.text_input('Username', value='demo')
|
88 |
+
password = st.text_input('Password', value='demo', type='password')
|
89 |
+
language = st.selectbox('Report Language', ['English', 'Spanish', 'French', 'German'])
|
90 |
+
|
91 |
+
# Analyze button
|
92 |
+
if st.button('Analyze'):
|
93 |
+
if uploaded_file and username and password:
|
94 |
+
response = analyze_blood_test(uploaded_file, username, password, language)
|
95 |
+
|
96 |
+
if response.status_code == 200:
|
97 |
+
st.success('Analysis completed successfully')
|
98 |
+
pdf_filename = f"{uploaded_file.name.split('.')[0]}_results.pdf"
|
99 |
+
|
100 |
+
with open(pdf_filename, 'wb') as pdf_file:
|
101 |
+
pdf_file.write(response.content)
|
102 |
+
|
103 |
+
with open(pdf_filename, 'rb') as pdf_file:
|
104 |
+
st.download_button('Download PDF Report', data=pdf_file, file_name=pdf_filename)
|
105 |
+
else:
|
106 |
+
st.error(f"Failed to analyze file. Status code: {response.status_code}, Message: {response.json()}")
|
107 |
+
else:
|
108 |
+
st.warning('Please fill in all fields and upload a file.')
|
109 |
+
|
110 |
+
if __name__ == '__main__':
|
111 |
+
main()
|