AI-RESEARCHER-2024 commited on
Commit
f0fcd1a
·
verified ·
1 Parent(s): 24760c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -8,12 +8,11 @@ from tensorflow.keras.models import load_model
8
  from PIL import Image, ImageDraw, ImageFont
9
  from ultralytics import YOLO
10
  import cv2
11
- from huggingface_hub import from_pretrained_keras
12
 
13
  class Config:
14
- ASSETS_DIR = os.path.join(os.path.dirname(__file__), 'assets')
15
- MODELS_DIR = os.path.join(ASSETS_DIR, 'models')
16
- FONT_DIR = os.path.join(ASSETS_DIR, 'arial.ttf')
17
  MODELS = {
18
  "Calculus and Caries Classification": "classification.h5",
19
  "Caries Detection": "detection.pt",
@@ -30,10 +29,7 @@ class ModelManager:
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
- 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:
@@ -256,6 +252,16 @@ class GradioInterface:
256
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
257
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
258
  {app_styles}
 
 
 
 
 
 
 
 
 
 
259
  <div class="app-header">
260
  <h1 class="app-title">AI in Dentistry</h1>
261
  <h2 class="app-subtitle"> Advancing Imaging and Clinical Transcription</h2>
@@ -265,6 +271,16 @@ class GradioInterface:
265
  </div>
266
  """
267
 
 
 
 
 
 
 
 
 
 
 
268
  def process_image(image, model_name):
269
  result = self.image_processor.process_image(image, model_name)
270
  return result
@@ -273,7 +289,7 @@ class GradioInterface:
273
  examples = self.preloaded_examples[model_name]
274
  return gr.Dataset(samples=[[example] for example in examples])
275
 
276
- with gr.Blocks() as demo:
277
  gr.HTML(header_html)
278
  with gr.Row(elem_classes="content-container"):
279
  with gr.Column():
@@ -312,4 +328,5 @@ def main():
312
  demo.launch(share=False)
313
 
314
  if __name__ == "__main__":
315
- main()
 
 
8
  from PIL import Image, ImageDraw, ImageFont
9
  from ultralytics import YOLO
10
  import cv2
 
11
 
12
  class Config:
13
+ ASSETS_DIR = './assets'
14
+ MODELS_DIR = './models'
15
+ FONT_DIR = './assets/arial.ttf'
16
  MODELS = {
17
  "Calculus and Caries Classification": "classification.h5",
18
  "Caries Detection": "detection.pt",
 
29
  def load_model(model_name: str):
30
  model_path = os.path.join(Config.MODELS_DIR, Config.MODELS[model_name])
31
  if model_name == "Dental X-Ray Segmentation":
32
+ return tf.keras.models.load_model(model_path)
 
 
 
33
  elif model_name == "Caries Detection":
34
  return YOLO(model_path)
35
  else:
 
252
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
253
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
254
  {app_styles}
255
+ <div class="app-header">
256
+ <h1 class="app-title">AI Dentistry Application</h1>
257
+ <h2 class="app-subtitle">Model Selection and Image Processing</h2>
258
+ <p class="app-description">
259
+ This application allows you to select different models for dental image processing tasks.
260
+ </p>
261
+ </div>
262
+ """
263
+
264
+ header_html = f"""
265
  <div class="app-header">
266
  <h1 class="app-title">AI in Dentistry</h1>
267
  <h2 class="app-subtitle"> Advancing Imaging and Clinical Transcription</h2>
 
271
  </div>
272
  """
273
 
274
+ js_func = """
275
+ function refresh() {
276
+ const url = new URL(window.location);
277
+ if (url.searchParams.get('__theme') !== 'dark') {
278
+ url.searchParams.set('__theme', 'dark');
279
+ window.location.href = url.href;
280
+ }
281
+ }
282
+ """
283
+
284
  def process_image(image, model_name):
285
  result = self.image_processor.process_image(image, model_name)
286
  return result
 
289
  examples = self.preloaded_examples[model_name]
290
  return gr.Dataset(samples=[[example] for example in examples])
291
 
292
+ with gr.Blocks(js=js_func, theme=gr.themes.Default()):
293
  gr.HTML(header_html)
294
  with gr.Row(elem_classes="content-container"):
295
  with gr.Column():
 
328
  demo.launch(share=False)
329
 
330
  if __name__ == "__main__":
331
+ main()
332
+