Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -64,8 +64,7 @@ def extract_pdf_report_and_redirect(pdf):
|
|
64 |
with pdfplumber.open(pdf.name) as pdf_file:
|
65 |
for page in pdf_file.pages:
|
66 |
text += page.extract_text()
|
67 |
-
|
68 |
-
return text, gr.update(selected=True)
|
69 |
|
70 |
def predict_eye_disease(input_image):
|
71 |
input_image = tf.image.resize(input_image, [224, 224]) / 255.0
|
@@ -114,106 +113,56 @@ def doctor_dashboard(password):
|
|
114 |
return "\n\n".join(details)
|
115 |
|
116 |
# Gradio App Layout
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
register_button = gr.Button("Register")
|
128 |
-
registration_output = gr.Textbox(label="Output", interactive=False)
|
129 |
-
|
130 |
-
register_button.click(
|
131 |
-
fn=register_patient,
|
132 |
-
inputs=[name, age, gender, password],
|
133 |
-
outputs=registration_output,
|
134 |
-
)
|
135 |
-
|
136 |
-
with gr.Tab("Analyze Medical Report") as analyze_tab:
|
137 |
-
patient_id = gr.Number(label="Patient ID")
|
138 |
-
report_text = gr.Textbox(label="Report Text")
|
139 |
-
analyze_button = gr.Button("Analyze")
|
140 |
-
analysis_output = gr.Textbox(label="Analysis Output", interactive=False)
|
141 |
-
|
142 |
-
analyze_button.click(
|
143 |
-
fn=analyze_report,
|
144 |
-
inputs=[patient_id, report_text],
|
145 |
-
outputs=analysis_output,
|
146 |
-
)
|
147 |
-
|
148 |
-
with gr.Tab("Extract PDF Report"):
|
149 |
-
pdf_file = gr.File(label="Upload PDF Report")
|
150 |
-
extract_button = gr.Button("Extract and Analyze")
|
151 |
-
|
152 |
-
extract_button.click(
|
153 |
-
fn=extract_pdf_report_and_redirect,
|
154 |
-
inputs=pdf_file,
|
155 |
-
outputs=[
|
156 |
-
report_text, # Automatically populate the report text in the Analyze tab
|
157 |
-
analyze_tab, # Redirect to the Analyze Medical Report tab
|
158 |
-
],
|
159 |
-
)
|
160 |
-
|
161 |
-
with gr.Tab("Opthamologist Space"):
|
162 |
-
eye_image = gr.Image(label="Upload an Eye Image", type="numpy")
|
163 |
-
eye_result = gr.Textbox(label="Eye Disease Prediction", interactive=False)
|
164 |
-
predict_button = gr.Button("Predict")
|
165 |
-
|
166 |
-
predict_button.click(
|
167 |
-
fn=predict_eye_disease,
|
168 |
-
inputs=eye_image,
|
169 |
-
outputs=eye_result,
|
170 |
-
)
|
171 |
-
|
172 |
-
with gr.Tab("Doctor Space"):
|
173 |
-
doc_patient_id = gr.Number(label="Patient ID")
|
174 |
-
doctor_output = gr.Textbox(label="Doctor Details", interactive=False)
|
175 |
-
doctor_button = gr.Button("Get Details")
|
176 |
-
|
177 |
-
doctor_button.click(
|
178 |
-
fn=doctor_space,
|
179 |
-
inputs=doc_patient_id,
|
180 |
-
outputs=doctor_output,
|
181 |
-
)
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
)
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
doc_dashboard_button.click(
|
212 |
-
fn=doctor_dashboard,
|
213 |
-
inputs=doc_password,
|
214 |
-
outputs=doc_dashboard_output,
|
215 |
-
)
|
216 |
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
-
|
|
|
64 |
with pdfplumber.open(pdf.name) as pdf_file:
|
65 |
for page in pdf_file.pages:
|
66 |
text += page.extract_text()
|
67 |
+
return text, gr.Tabs.update(selected="Analyze Medical Report")
|
|
|
68 |
|
69 |
def predict_eye_disease(input_image):
|
70 |
input_image = tf.image.resize(input_image, [224, 224]) / 255.0
|
|
|
113 |
return "\n\n".join(details)
|
114 |
|
115 |
# Gradio App Layout
|
116 |
+
with gr.Blocks() as app:
|
117 |
+
gr.Markdown("# Medico GPT")
|
118 |
+
|
119 |
+
with gr.Tab("Patient Registration"):
|
120 |
+
name = gr.Textbox(label="Patient Name")
|
121 |
+
age = gr.Number(label="Age")
|
122 |
+
gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
|
123 |
+
password = gr.Textbox(label="Set Password", type="password")
|
124 |
+
register_button = gr.Button("Register")
|
125 |
+
register_output = gr.Textbox(label="Output")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
+
register_button.click(
|
128 |
+
fn=register_patient,
|
129 |
+
inputs=[name, age, gender, password],
|
130 |
+
outputs=register_output
|
131 |
+
)
|
132 |
+
|
133 |
+
with gr.Tab("Analyze Medical Report") as analyze_tab:
|
134 |
+
patient_id = gr.Number(label="Patient ID")
|
135 |
+
report_text = gr.Textbox(label="Report Text")
|
136 |
+
analyze_button = gr.Button("Analyze")
|
137 |
+
analyze_output = gr.Textbox(label="Output")
|
138 |
|
139 |
+
analyze_button.click(
|
140 |
+
fn=analyze_report,
|
141 |
+
inputs=[patient_id, report_text],
|
142 |
+
outputs=analyze_output
|
143 |
+
)
|
144 |
+
|
145 |
+
with gr.Tab("Extract PDF Report"):
|
146 |
+
pdf_file = gr.File(label="Upload PDF")
|
147 |
+
extract_output = gr.Textbox(label="Extracted Text")
|
148 |
+
extract_button = gr.Button("Extract and Analyze")
|
|
|
149 |
|
150 |
+
extract_button.click(
|
151 |
+
fn=extract_pdf_report_and_redirect,
|
152 |
+
inputs=pdf_file,
|
153 |
+
outputs=[report_text, gr.Tabs.update(selected="Analyze Medical Report")]
|
154 |
+
)
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
+
with gr.Tab("Patient Dashboard"):
|
157 |
+
dashboard_id = gr.Number(label="Patient ID")
|
158 |
+
dashboard_password = gr.Textbox(label="Password", type="password")
|
159 |
+
dashboard_output = gr.Textbox(label="Dashboard Info")
|
160 |
+
dashboard_button = gr.Button("Access")
|
161 |
+
|
162 |
+
dashboard_button.click(
|
163 |
+
fn=patient_dashboard,
|
164 |
+
inputs=[dashboard_id, dashboard_password],
|
165 |
+
outputs=dashboard_output
|
166 |
+
)
|
167 |
|
168 |
+
app.launch(share=True)
|