AI-RESEARCHER-2024 commited on
Commit
539cc78
1 Parent(s): 04c696b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -31,16 +31,14 @@ class ModelManager:
31
  model_path = os.path.join(Config.MODELS_DIR, Config.MODELS[model_name])
32
  if model_name == "Dental X-Ray Segmentation":
33
  try:
34
- model = from_pretrained_keras("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net")
35
  except:
36
- model = tf.keras.models.load_model(model_path)
37
- return model
38
  elif model_name == "Caries Detection":
39
  return YOLO(model_path)
40
  else:
41
  return load_model(model_path)
42
 
43
-
44
  class ImageProcessor:
45
 
46
  def process_image(self, image: Image.Image, model_name: str):
@@ -124,7 +122,6 @@ class ImageProcessor:
124
  img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
125
  return img
126
 
127
-
128
  class GradioInterface:
129
  def __init__(self):
130
  self.image_processor = ImageProcessor()
@@ -266,16 +263,6 @@ class GradioInterface:
266
  </div>
267
  """
268
 
269
- header_html = f"""
270
- <div class="app-header">
271
- <h1 class="app-title">AI in Dentistry</h1>
272
- <h2 class="app-subtitle"> Advancing Imaging and Clinical Transcription</h2>
273
- <p class="app-description">
274
- This application demonstrates the use of AI in dentistry for tasks such as classification, detection, and segmentation.
275
- </p>
276
- </div>
277
- """
278
-
279
  js_func = """
280
  function refresh() {
281
  const url = new URL(window.location);
@@ -305,10 +292,21 @@ class GradioInterface:
305
  choices=list(Config.MODELS.keys()),
306
  value="Calculus and Caries Classification",
307
  )
308
- examples = gr.Examples(
 
309
  inputs=input_image,
310
  examples=self.preloaded_examples["Calculus and Caries Classification"],
311
  )
 
 
 
 
 
 
 
 
 
 
312
  with gr.Column():
313
  result = gr.Image(label="Result", elem_classes="image-preview")
314
  run_button = gr.Button("Run", elem_classes="gr-button")
@@ -316,7 +314,7 @@ class GradioInterface:
316
  model_name.change(
317
  fn=update_examples,
318
  inputs=model_name,
319
- outputs=examples.dataset,
320
  )
321
 
322
  run_button.click(
@@ -330,8 +328,7 @@ class GradioInterface:
330
  def main():
331
  interface = GradioInterface()
332
  demo = interface.create_interface()
333
- demo.launch(share=False)
334
 
335
  if __name__ == "__main__":
336
- main()
337
-
 
31
  model_path = os.path.join(Config.MODELS_DIR, Config.MODELS[model_name])
32
  if model_name == "Dental X-Ray Segmentation":
33
  try:
34
+ return from_pretrained_keras("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net")
35
  except:
36
+ return tf.keras.models.load_model(model_path)
 
37
  elif model_name == "Caries Detection":
38
  return YOLO(model_path)
39
  else:
40
  return load_model(model_path)
41
 
 
42
  class ImageProcessor:
43
 
44
  def process_image(self, image: Image.Image, model_name: str):
 
122
  img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
123
  return img
124
 
 
125
  class GradioInterface:
126
  def __init__(self):
127
  self.image_processor = ImageProcessor()
 
263
  </div>
264
  """
265
 
 
 
 
 
 
 
 
 
 
 
266
  js_func = """
267
  function refresh() {
268
  const url = new URL(window.location);
 
292
  choices=list(Config.MODELS.keys()),
293
  value="Calculus and Caries Classification",
294
  )
295
+ examples_classification = gr.Examples(
296
+ label="Classification Examples",
297
  inputs=input_image,
298
  examples=self.preloaded_examples["Calculus and Caries Classification"],
299
  )
300
+ examples_detection = gr.Examples(
301
+ label="Caries Detection Examples",
302
+ inputs=input_image,
303
+ examples=self.preloaded_examples["Caries Detection"],
304
+ )
305
+ examples_segmentation = gr.Examples(
306
+ label="Segmentation Examples",
307
+ inputs=input_image,
308
+ examples=self.preloaded_examples["Dental X-Ray Segmentation"],
309
+ )
310
  with gr.Column():
311
  result = gr.Image(label="Result", elem_classes="image-preview")
312
  run_button = gr.Button("Run", elem_classes="gr-button")
 
314
  model_name.change(
315
  fn=update_examples,
316
  inputs=model_name,
317
+ outputs=[examples_classification.dataset, examples_detection.dataset, examples_segmentation.dataset],
318
  )
319
 
320
  run_button.click(
 
328
  def main():
329
  interface = GradioInterface()
330
  demo = interface.create_interface()
331
+ demo.launch(debug=True)
332
 
333
  if __name__ == "__main__":
334
+ main()