nagur-shareef-shaik commited on
Commit
21ff138
·
1 Parent(s): 5ebed13

Add Application file

Browse files
Files changed (4) hide show
  1. .gitignore +5 -0
  2. app.py +134 -0
  3. requirements.txt +10 -0
  4. setup.py +22 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ *__pycache__
2
+ logs/
3
+ medeyecare_venv/
4
+ *.egg-info
5
+ *.DS_Store
app.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+ import shutil
5
+ from pathlib import Path
6
+
7
+ # Define API endpoint
8
+ API_URL = "https://nagur-shareef-shaik-retinal-health-diagnostics.hf.space/predict"
9
+ SPACE_URL = "https://nagur-shareef-shaik-medeyecare.hf.space/"
10
+
11
+ # Ensure uploads directory exists
12
+ UPLOAD_FOLDER = "uploads"
13
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
14
+
15
+ ###### Sidebar ######
16
+
17
+ # Custom CSS to make the sidebar fixed and adjust width
18
+ st.markdown(
19
+ """
20
+ <style>
21
+ [data-testid="stSidebar"] {
22
+ width: 750px !important; /* Adjust width as needed */
23
+ background-color: #f8f9fa; /* Light grey background */
24
+ }
25
+ [data-testid="stSidebarNav"] {
26
+ position: fixed;
27
+ width: 750px;
28
+ }
29
+ </style>
30
+ """,
31
+ unsafe_allow_html=True,
32
+ )
33
+
34
+ st.sidebar.header("Intelligent Application for Retinal Diseases Diagnosis")
35
+ st.sidebar.image("images/rhd_img_1.jpeg", width=1250)
36
+
37
+ st.sidebar.markdown("""
38
+ ### Get AI-Powered Diagnosis Report
39
+
40
+ 1. **Enter Patient Details**
41
+ - Name, Age, Gender, Contact Information, Address
42
+ - Select Diagnosis Task (**General, Retinopathy, DME, Cataracts**)
43
+ - **General:** Diagnoses Diabetic Retinopathy, Cataracts, Glaucoma, & Normal conditions from retinal fundus images.
44
+ - **Retinopathy:** Detects 7 retinopathy severity grades (No DR, Mild NPDR, Moderate NPDR, Severe NPDR, Very Severe NPDR, PDR, and Advanced PDR) from retinal scans.
45
+ - **DME:** Identifies the presence of Diabetic Macular Edema (DME) from retinal scans.
46
+ - **Cataracts:** Diagnoses Cataracts from digital eye images.
47
+ - Add Medical Notes (if any)
48
+
49
+ 2. **Upload Retinal Scan**
50
+ - Accepts **JPG, JPEG, PNG** formats
51
+ - Ensure clear, high-quality images
52
+
53
+ 3. **Submit for AI Analysis**
54
+ - Click **"Submit Request"** to send details to AI model
55
+ - AI processes the image and generates a diagnosis
56
+
57
+ 4. **View Results Instantly**
58
+ - AI-powered diagnosis displayed with insights
59
+ - Download or share the report if needed
60
+
61
+ """)
62
+
63
+ # Create two columns
64
+ col1, col2 = st.columns([1, 3]) # Adjust the width ratio as needed
65
+
66
+ with col1:
67
+ st.image("images/rhd-logo.png", width=300) # Adjust width as needed
68
+
69
+ with col2:
70
+ st.title("Retinal Health Diagnostics")
71
+
72
+ # User input fields
73
+ task = st.selectbox("Select Task", ["general", "retinopathy", "dme", "cataracts"], index=0)
74
+ name = st.text_input("Name")
75
+ a, b, c = st.columns([1, 1, 1])
76
+ with a:
77
+ age = st.text_input("Age")
78
+ with b:
79
+ gender = st.selectbox("Gender", ["Male", "Female", "Other"], index=0)
80
+ with c:
81
+ phone = st.text_input("Phone")
82
+ email = st.text_input("Email")
83
+ address = st.text_area("Address")
84
+ med_notes = st.text_area("Medical Notes")
85
+
86
+ # Image upload
87
+ uploaded_file = st.file_uploader("Upload Retinal Image", type=["jpg", "jpeg", "png"])
88
+
89
+ if uploaded_file:
90
+ file_path = os.path.join(Path(UPLOAD_FOLDER), uploaded_file.name)
91
+ # Save file in Hugging Face Space storage
92
+ with open(file_path, "wb") as f:
93
+ f.write(uploaded_file.getbuffer())
94
+
95
+ # Generate the public URL of the saved image
96
+ image_url = f"{SPACE_URL}/{UPLOAD_FOLDER}/{uploaded_file.name}"
97
+
98
+ st.success(f"Image uploaded! Accessible at: {image_url}")
99
+ st.image(image_url, caption="Uploaded Image")
100
+
101
+ # Submit button
102
+ if st.button("Submit Request"):
103
+ if not uploaded_file:
104
+ st.error("Please upload an image.")
105
+ else:
106
+ # Create request payload
107
+ payload = {
108
+ "task": task,
109
+ "img_path": str(file_path),
110
+ "name": name,
111
+ "age": age,
112
+ "gender": gender,
113
+ "address": address,
114
+ "phone": phone,
115
+ "email": email,
116
+ "med_notes": med_notes,
117
+ }
118
+
119
+ try:
120
+ response = requests.post(API_URL, json=payload)
121
+ if response.status_code == 200:
122
+ st.success("Diagnosis Complete!")
123
+
124
+ predicted_class = response.json().get("test_results", {}).get("predicted_class", None)
125
+ confidence = response.json().get("test_results", {}).get("confidence", None)
126
+ attention_map = response.json().get("test_results", {}).get("attention_map", None)
127
+
128
+ st.image(attention_map)
129
+ st.write(f"Result: **{predicted_class}** with confidance {confidence*100} %")
130
+ # st.json(response.json())
131
+ else:
132
+ st.error(f"Error {response.status_code}: {response.text}")
133
+ except requests.exceptions.RequestException as e:
134
+ st.error(f"Request failed: {e}")
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy
2
+ pandas
3
+ matplotlib
4
+ tqdm
5
+ scikit-learn
6
+ opencv-python
7
+ tensorflow
8
+ streamlit
9
+ uvicorn
10
+ fastapi
setup.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup, find_packages
2
+ from typing import List
3
+
4
+ HYPEN_E_DOT='-e .'
5
+ def get_requirements(filepath:str) -> List[str]:
6
+ with open(filepath) as file:
7
+ requirements = file.readlines()
8
+ requirements = [req.replace("\n", "") for req in requirements]
9
+ if HYPEN_E_DOT in requirements:
10
+ requirements.remove(HYPEN_E_DOT)
11
+
12
+ return requirements
13
+
14
+ setup(
15
+ name='medeyecare',
16
+ version='0.1.0',
17
+ description='Retinal Diseases Classification based on Guided Context Gating Attention',
18
+ author='Nagur Shareef Shaik',
19
+ author_email='shaiknagurshareef6@gmail.com',
20
+ packages=find_packages(),
21
+ install_requires=get_requirements('requirements.txt')
22
+ )