Spaces:
Runtime error
Runtime error
import streamlit as st | |
import requests | |
# API processing function | |
def analyze_blood_test(file, username, password, language='English'): | |
url = 'https://app.aibloodtestinterpret.com/api/analyze' | |
files = {'file': (file.name, file, 'multipart/form-data')} | |
data = {'username': username, 'password': password, 'language': language} | |
response = requests.post(url, files=files, data=data) | |
return response | |
# Main function for the Streamlit app | |
def main(): | |
# Custom CSS styling for the app | |
st.markdown( | |
""" | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f8f9fa; | |
color: #343a40; | |
} | |
.main { | |
background-color: #ffffff; | |
padding: 2rem; | |
border-radius: 0.5rem; | |
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1); | |
} | |
h1 { | |
color: #007bff; | |
font-size: 2.5rem; | |
text-align: center; | |
margin-bottom: 2rem; | |
} | |
h2, h3, h4 { | |
color: #0056b3; | |
} | |
.sidebar .sidebar-content { | |
background-color: #e9ecef; | |
padding: 2rem; | |
border-radius: 0.5rem; | |
} | |
.stButton>button { | |
background-color: #007bff; | |
color: white; | |
border-radius: 0.25rem; | |
padding: 0.75rem 1.5rem; | |
font-size: 1rem; | |
cursor: pointer; | |
} | |
.stButton>button:hover { | |
background-color: #0056b3; | |
} | |
.stDownloadButton>button { | |
background-color: #28a745; | |
color: white; | |
border-radius: 0.25rem; | |
padding: 0.75rem 1.5rem; | |
font-size: 1rem; | |
cursor: pointer; | |
} | |
.stDownloadButton>button:hover { | |
background-color: #218838; | |
} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
# App main content | |
st.markdown( | |
""" | |
<div style="text-align: center; margin-bottom: 40px;"> | |
<img src="https://lh5.googleusercontent.com/acxDsEgG6qumlBmHKsNK1j8kxa4Z4Tsq1QBLBBydVKMGOyH3Qn1JU5AklbDis3SlVO_mY7KSVPnkzhul_5Zxr_023IU_UY0cxVG-VhY1nTj7A-ritWtDEAswMCo0jVMkdw=w2560" alt="AI Blood Test Interpretation Logo" width="300"> | |
</div> | |
""", | |
unsafe_allow_html=True | |
) | |
st.sidebar.title('About') | |
st.sidebar.info('''\ | |
### Free Trial Available | |
Take advantage of our limited-time free trial for all humanity. | |
''') | |
st.sidebar.info('''\ | |
### Product Release | |
After 1.5 years of diligent effort, the AI Blood Test Interpretation tool is now officially launched. | |
''') | |
st.sidebar.info('''\ | |
### AI Inventor Contact | |
For any inquiries, please contact: [email protected] | |
''') | |
st.write('Welcome to the AI-driven Blood Test Interpreter. Upload your blood test file and get a detailed analysis within seconds.') | |
uploaded_file = st.file_uploader('Upload your blood test image or PDF', type=['jpg', 'jpeg', 'png', 'pdf']) | |
username = st.text_input('Username', value='demo') | |
password = st.text_input('Password', value='demo', type='password') | |
languages = [ | |
'English', 'Spanish', 'French', 'German', 'Italian', 'Portuguese', 'Dutch', | |
'Japanese', 'Chinese', 'Korean', 'Russian', 'Arabic', 'Hindi', 'Bengali', | |
'Turkish', 'Swedish', 'Norwegian', 'Danish', 'Finnish', 'Greek', 'Hebrew', | |
'Polish', 'Czech', 'Hungarian', 'Romanian', 'Bulgarian', 'Serbian', 'Croatian', | |
'Slovak', 'Slovenian', 'Ukrainian', 'Belarusian', 'Latvian', 'Lithuanian', | |
'Estonian', 'Macedonian', 'Albanian', 'Bosnian', 'Irish', 'Maltese', | |
'Icelandic', 'Welsh', 'Galician', 'Basque', 'Catalan', 'Afrikaans', | |
'Swahili', 'Zulu', 'Xhosa', 'Amharic', 'Yoruba', 'Igbo', 'Somali', | |
'Vietnamese', 'Thai', 'Filipino', 'Malay', 'Indonesian', 'Mongolian', | |
'Khmer', 'Sinhala', 'Burmese', 'Lao', 'Marathi', 'Gujarati', 'Punjabi', | |
'Tamil', 'Telugu', 'Kannada', 'Malayalam', 'Oriya', 'Assamese', | |
'Nepali', 'Pashto', 'Farsi', 'Urdu', 'Kurdish', 'Uzbek', 'Kazakh', | |
'Tajik', 'Turkmen', 'Kyrgyz', 'Azerbaijani', 'Armenian', 'Georgian', | |
'Haitian Creole', 'Javanese', 'Sundanese', 'Madurese', 'Minangkabau', | |
'Acehnese', 'Balinese', 'Batak', 'Buginese', 'Rejang', 'Sasak' | |
] | |
language = st.selectbox('Report Language', languages) | |
# Analyze button | |
if st.button('Analyze'): | |
if uploaded_file and username and password: | |
response = analyze_blood_test(uploaded_file, username, password, language) | |
if response.status_code == 200: | |
st.success('Analysis completed successfully') | |
pdf_filename = f"{uploaded_file.name.split('.')[0]}_results.pdf" | |
with open(pdf_filename, 'wb') as pdf_file: | |
pdf_file.write(response.content) | |
with open(pdf_filename, 'rb') as pdf_file: | |
st.download_button('Download PDF Report', data=pdf_file, file_name=pdf_filename) | |
else: | |
st.error(f"Failed to analyze file. Status code: {response.status_code}, Message: {response.json()}") | |
else: | |
st.warning('Please fill in all fields and upload a file.') | |
if __name__ == '__main__': | |
main() |