ahmed-7124 commited on
Commit
205a28b
·
verified ·
1 Parent(s): 7f3ddca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -100
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
- # Redirect to the "Analyze Medical Report" tab and populate the extracted text
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
- def app_layout():
118
- with gr.Blocks() as app:
119
- gr.Markdown("# Medico GPT")
120
-
121
- with gr.Tab("Patient Registration"):
122
- with gr.Row():
123
- name = gr.Textbox(label="Patient Name")
124
- age = gr.Number(label="Age")
125
- gender = gr.Radio(label="Gender", choices=["Male", "Female", "Other"])
126
- password = gr.Textbox(label="Set Password", type="password")
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
- with gr.Tab("Pharmacist Space"):
184
- pharm_patient_id = gr.Number(label="Patient ID")
185
- pharmacist_output = gr.Textbox(label="Pharmacist Details", interactive=False)
186
- pharmacist_button = gr.Button("Get Details")
187
-
188
- pharmacist_button.click(
189
- fn=pharmacist_space,
190
- inputs=pharm_patient_id,
191
- outputs=pharmacist_output,
192
- )
 
193
 
194
- with gr.Tab("Patient Dashboard"):
195
- dash_patient_id = gr.Number(label="Patient ID")
196
- dash_password = gr.Textbox(label="Password", type="password")
197
- dashboard_output = gr.Textbox(label="Patient Dashboard", interactive=False)
198
- dashboard_button = gr.Button("Access Dashboard")
199
-
200
- dashboard_button.click(
201
- fn=patient_dashboard,
202
- inputs=[dash_patient_id, dash_password],
203
- outputs=dashboard_output,
204
- )
205
 
206
- with gr.Tab("Doctor Dashboard"):
207
- doc_password = gr.Textbox(label="Doctor Password", type="password")
208
- doc_dashboard_output = gr.Textbox(label="Doctor Dashboard", interactive=False)
209
- doc_dashboard_button = gr.Button("Access Dashboard")
210
-
211
- doc_dashboard_button.click(
212
- fn=doctor_dashboard,
213
- inputs=doc_password,
214
- outputs=doc_dashboard_output,
215
- )
216
 
217
- return app
 
 
 
 
 
 
 
 
 
 
218
 
219
- app_layout().launch(share=True)
 
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)