Skip to content

Page medical

app()

Medical Examination Analysis Page.

This app allows users to upload files and analyze medical examinations by sending the file to a backend API.

Source code in view/streamlit_app/page_medical.py
 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
def app():
    """
    Medical Examination Analysis Page.

    This app allows users to upload files and analyze medical examinations 
    by sending the file to a backend API.
    """
    st.title("Medical Examination Analysis")
    st.markdown("""
                Welcome to the Medical Examination Analysis module.
                Please upload a document for analysis.
                """
                )

    st.selectbox(
        label="Choose the language for the response",
        options = [
                    "🇺🇸 English",
                    "🇧🇷 Portuguese",
                    "🇪🇸 Spanish",
                    "🇫🇷 French",
                    "🇩🇪 German",
                    "🇮🇹 Italian",
                    "🇨🇳 Chinese (Simplified)",
                    "🇯🇵 Japanese",
                    "🇷🇺 Russian",
                    "🇵🇱 Polish",
                    "🇰🇷 Korean",
                    "🇮🇳 Hindi",
                    "🇦🇪 Arabic",
                    "🇲🇽 Spanish (Mexico)",
                    "🇿🇦 Zulu",
                    "🇳🇬 Yoruba",
                    "🇹🇭 Thai",
                    "🇮🇩 Indonesian",
                    "🇵🇭 Filipino",
                    "🇨🇦 English (Canada)",
                    "🇦🇺 English (Australia)"
                ],
        index=0,
        key="language_option"
    )

    uploaded_file = st.file_uploader(
        label="Upload your document here",  
        # type=['pdf', 'docx', 'xlsx', 'csv', 'md', 'txt'], 
        key='uploaded_file', 
        accept_multiple_files=False
        )

    if uploaded_file:
        button_run = st.button('Run Analysis')
        if button_run:
            type_of_analysis = 'medical'
            task_id = str(random.randint(0, 9999))  # Generate a random task ID

            if 'user' not in st.session_state:
                st.session_state['user'] = 'default_user'

            try:
                response_upload = upload_file(uploaded_file, task_id, type_of_analysis, st.session_state['user'])
                if response_upload:
                    parameters = {
                        "user": st.session_state['user'],
                        "task_id": task_id,
                        "type_of_analysis": type_of_analysis,
                        "service": st.session_state["service_option"],
                        "language": st.session_state["language_option"]
                    }
                    st.write("Parameters sent for analysis:", parameters)

                    api_route = '/medical'
                    task_response = call_endpoint(api_route, parameters)
                    if task_response.get('error'):
                        st.error(f"Error: {task_response['error']}")
                    else:
                        st.success("Successfully sent for analysis! Check the status and response in the side menu.")
                else:
                    st.error("Failed to upload the file. Please try again.")
            except Exception as e:
                st.error(f"An unexpected error occurred: {e}")