AI-RESEARCHER-2024 commited on
Commit
04c696b
1 Parent(s): 5e5654c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -10,7 +10,6 @@ from ultralytics import YOLO
10
  import cv2
11
  from huggingface_hub import from_pretrained_keras
12
 
13
-
14
  class Config:
15
  ASSETS_DIR = './assets'
16
  MODELS_DIR = './models'
@@ -31,12 +30,17 @@ class ModelManager:
31
  def load_model(model_name: str):
32
  model_path = os.path.join(Config.MODELS_DIR, Config.MODELS[model_name])
33
  if model_name == "Dental X-Ray Segmentation":
34
- return from_pretrained_keras("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net")
 
 
 
 
35
  elif model_name == "Caries Detection":
36
  return YOLO(model_path)
37
  else:
38
  return load_model(model_path)
39
 
 
40
  class ImageProcessor:
41
 
42
  def process_image(self, image: Image.Image, model_name: str):
@@ -120,6 +124,7 @@ class ImageProcessor:
120
  img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
121
  return img
122
 
 
123
  class GradioInterface:
124
  def __init__(self):
125
  self.image_processor = ImageProcessor()
@@ -261,6 +266,16 @@ class GradioInterface:
261
  </div>
262
  """
263
 
 
 
 
 
 
 
 
 
 
 
264
  js_func = """
265
  function refresh() {
266
  const url = new URL(window.location);
@@ -290,21 +305,10 @@ class GradioInterface:
290
  choices=list(Config.MODELS.keys()),
291
  value="Calculus and Caries Classification",
292
  )
293
- examples_classification = gr.Examples(
294
- label="Classification Examples",
295
  inputs=input_image,
296
  examples=self.preloaded_examples["Calculus and Caries Classification"],
297
  )
298
- examples_detection = gr.Examples(
299
- label="Caries Detection Examples",
300
- inputs=input_image,
301
- examples=self.preloaded_examples["Caries Detection"],
302
- )
303
- examples_segmentation = gr.Examples(
304
- label="Segmentation Examples",
305
- inputs=input_image,
306
- examples=self.preloaded_examples["Dental X-Ray Segmentation"],
307
- )
308
  with gr.Column():
309
  result = gr.Image(label="Result", elem_classes="image-preview")
310
  run_button = gr.Button("Run", elem_classes="gr-button")
@@ -312,7 +316,7 @@ class GradioInterface:
312
  model_name.change(
313
  fn=update_examples,
314
  inputs=model_name,
315
- outputs=[examples_classification.dataset, examples_detection.dataset, examples_segmentation.dataset],
316
  )
317
 
318
  run_button.click(
@@ -329,4 +333,5 @@ def main():
329
  demo.launch(share=False)
330
 
331
  if __name__ == "__main__":
332
- main()
 
 
10
  import cv2
11
  from huggingface_hub import from_pretrained_keras
12
 
 
13
  class Config:
14
  ASSETS_DIR = './assets'
15
  MODELS_DIR = './models'
 
30
  def load_model(model_name: str):
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
  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
  </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
  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
  model_name.change(
317
  fn=update_examples,
318
  inputs=model_name,
319
+ outputs=examples.dataset,
320
  )
321
 
322
  run_button.click(
 
333
  demo.launch(share=False)
334
 
335
  if __name__ == "__main__":
336
+ main()
337
+