SM1108 commited on
Commit
ee6a113
·
verified ·
1 Parent(s): ff07952

added wrinkle detection

Browse files
Files changed (1) hide show
  1. main.py +19 -11
main.py CHANGED
@@ -12,7 +12,8 @@ PY_MODULES = {
12
  "inflammation.py": "RednessDetector",
13
  "texture.py": "TextureDetector",
14
  "skin_tone.py": "SkinToneDetector",
15
- "oiliness.py": "OilinessDetector" # Added oiliness module
 
16
  }
17
 
18
  def dynamic_import(module_path, class_name):
@@ -38,40 +39,47 @@ for py_file, class_name in PY_MODULES.items():
38
  # --- Skin analysis function using downloaded detectors ---
39
  def analyze_skin(image: np.ndarray, analysis_type: str) -> np.ndarray:
40
  output = image.copy()
41
- if analysis_type == "dark circles":
42
  detector = detector_classes["DarkCircleDetector"](image)
43
  result = detector.predict_json()
44
  output = detector.draw_json()
45
- elif analysis_type == "redness":
46
  detector = detector_classes["RednessDetector"](image)
47
  result = detector.predict_json()
48
  output = result.get("overlay_image")
49
- elif analysis_type == "texture":
50
  detector = detector_classes["TextureDetector"](image)
51
  result = detector.predict_json()
52
- print(result)
53
  output = result.get("overlay_image")
54
- elif analysis_type == "skin tone":
55
  detector = detector_classes["SkinToneDetector"](image)
56
  result = detector.predict_json()
57
  output = result.get("output_image")
58
- elif analysis_type == "oiliness":
59
  detector = detector_classes["OilinessDetector"](image)
60
  result = detector.predict_json()
61
  if result.get("detected"):
62
  output = result.get("overlay_image")
63
- print(f"Oiliness scores: {result.get('scores')}")
64
- else:
65
- print(f"Oiliness detection error: {result.get('error')}")
 
 
 
 
 
 
66
  return output
67
 
 
68
  # --- Gradio Interface code ---
69
  app = gr.Interface(
70
  fn=analyze_skin,
71
  inputs=[
72
  gr.Image(type="numpy", label="Upload your face image"),
73
  gr.Radio(
74
- ["dark circles", "redness", "texture", "skin tone", "oiliness"], # Added oiliness option
75
  label="Select Skin Analysis Type"
76
  ),
77
  ],
 
12
  "inflammation.py": "RednessDetector",
13
  "texture.py": "TextureDetector",
14
  "skin_tone.py": "SkinToneDetector",
15
+ "oiliness.py": "OilinessDetector",
16
+ "wrinkle_unet.py": "WrinkleDetector"
17
  }
18
 
19
  def dynamic_import(module_path, class_name):
 
39
  # --- Skin analysis function using downloaded detectors ---
40
  def analyze_skin(image: np.ndarray, analysis_type: str) -> np.ndarray:
41
  output = image.copy()
42
+ if analysis_type == "Dark Circles":
43
  detector = detector_classes["DarkCircleDetector"](image)
44
  result = detector.predict_json()
45
  output = detector.draw_json()
46
+ elif analysis_type == "Redness":
47
  detector = detector_classes["RednessDetector"](image)
48
  result = detector.predict_json()
49
  output = result.get("overlay_image")
50
+ elif analysis_type == "Texture":
51
  detector = detector_classes["TextureDetector"](image)
52
  result = detector.predict_json()
53
+ # print(result)
54
  output = result.get("overlay_image")
55
+ elif analysis_type == "Skin Tone":
56
  detector = detector_classes["SkinToneDetector"](image)
57
  result = detector.predict_json()
58
  output = result.get("output_image")
59
+ elif analysis_type == "Oiliness":
60
  detector = detector_classes["OilinessDetector"](image)
61
  result = detector.predict_json()
62
  if result.get("detected"):
63
  output = result.get("overlay_image")
64
+ # print(f"Oiliness scores: {result.get('scores')}")
65
+ # else:
66
+ # print(f"Oiliness detection error: {result.get('error')}")
67
+ elif analysis_type == "Wrinkles":
68
+ detector = detector_classes["WrinkleDetector"](image)
69
+ result = detector.predict_json()
70
+ if result.get("detected") is not None:
71
+ output = detector.draw_json(result)
72
+
73
  return output
74
 
75
+
76
  # --- Gradio Interface code ---
77
  app = gr.Interface(
78
  fn=analyze_skin,
79
  inputs=[
80
  gr.Image(type="numpy", label="Upload your face image"),
81
  gr.Radio(
82
+ ["Dark Circles", "Redness", "Texture", "Skin Tone", "Oiliness", "Wrinkles"],
83
  label="Select Skin Analysis Type"
84
  ),
85
  ],