openfree commited on
Commit
d79b5d6
Β·
verified Β·
1 Parent(s): f7df980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +212 -34
app.py CHANGED
@@ -657,71 +657,249 @@ Please consult a dermatologist for accurate diagnosis and treatment.</em>
657
  top_class = next(iter(class_probs))
658
  top_confidence = class_probs[top_class]
659
 
660
- # Get disease information from database or generate default
661
- disease_info = self.disease_info_db.get(top_class.lower(), None)
662
 
663
- # If disease not in database, create default information
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  if disease_info is None:
665
- disease_info = {
666
- "name_ko": self._translate_disease_name(top_class),
667
- "severity": self._estimate_severity(top_class),
668
- "description_ko": f"{top_class}λŠ” ν”ΌλΆ€ μ§ˆν™˜μ˜ ν•œ μ’…λ₯˜λ‘œ, μ „λ¬Έμ˜ 진단이 ν•„μš”ν•©λ‹ˆλ‹€.",
669
- "treatment_ko": "μ •ν™•ν•œ 진단을 μœ„ν•΄ ν”ΌλΆ€κ³Ό μ „λ¬Έμ˜μ™€ μƒλ‹΄ν•˜μ‹œκΈ° λ°”λžλ‹ˆλ‹€."
670
- }
671
 
672
- # Create comprehensive GPT analysis
 
 
 
 
 
 
 
 
 
 
 
 
673
  analysis = f"""
674
  <div class="diagnosis-card">
675
  <h3>πŸ€– GPT-OSS 상세 뢄석 / GPT-OSS Detailed Analysis</h3>
676
 
677
  <div class="info-box">
678
- <h4>μ§„λ‹¨λœ μ§ˆν™˜ 정보 / Diagnosed Condition Information</h4>
679
- <p><strong>μ§ˆν™˜λͺ… / Disease:</strong> {top_class.title()} ({disease_info.get('name_ko', top_class)})</p>
680
  <p><strong>신뒰도 / Confidence:</strong> {top_confidence:.1%}</p>
681
- <p><strong>μ„€λͺ… / Description:</strong> {disease_info.get('description_ko', 'AI 뢄석 쀑...')}</p>
682
  </div>
683
 
 
 
 
 
 
 
 
 
684
  <div class="result-container">
685
  <h4>πŸ“ ꢌμž₯ μΉ˜λ£Œλ²• / Recommended Treatment</h4>
686
- <p>{disease_info.get('treatment_ko', 'μ „λ¬Έμ˜ 상담이 ν•„μš”ν•©λ‹ˆλ‹€.')}</p>
 
687
  </div>
688
 
689
  <div class="result-container">
690
  <h4>πŸ’Š μƒν™œ 관리 μ§€μΉ¨ / Lifestyle Management Guidelines</h4>
691
- <ul>
692
- <li>μΆ©λΆ„ν•œ μˆ˜λΆ„ 섭취와 보슡 μœ μ§€ / Maintain adequate hydration and moisturization</li>
693
- <li>자극적인 ν™”μž₯ν’ˆ μ‚¬μš© 자제 / Avoid irritating cosmetics</li>
694
- <li>κ·œμΉ™μ μΈ 수면과 슀트레슀 관리 / Regular sleep and stress management</li>
695
- <li>κ· ν˜• 작힌 식단 μœ μ§€ / Maintain a balanced diet</li>
696
- <li>μ μ ˆν•œ μžμ™Έμ„  차단 / Adequate sun protection</li>
697
- </ul>
698
  </div>
699
 
700
  <div class="result-container">
701
  <h4>πŸ₯ μ˜λ£Œμ§„ 상담 ν•„μš” μ‹œμ  / When to Consult Healthcare Provider</h4>
702
- <ul>
703
- <li>증상이 2μ£Ό 이상 지속될 경우 / If symptoms persist for more than 2 weeks</li>
704
- <li>ν†΅μ¦μ΄λ‚˜ 가렀움이 μ‹¬ν•œ 경우 / Severe pain or itching</li>
705
- <li>병변이 κΈ‰μ†νžˆ ν™•μ‚°λ˜λŠ” 경우 / Rapid spread of lesions</li>
706
- <li>λ°œμ—΄ λ“± μ „μ‹  증상이 λ™λ°˜λ˜λŠ” 경우 / Accompanied by systemic symptoms like fever</li>
707
- <li>μΌμƒμƒν™œμ— μ§€μž₯을 쀄 μ •λ„λ‘œ μ‹¬ν•œ 경우 / Severe enough to interfere with daily life</li>
708
- </ul>
709
  </div>
710
 
711
  <div class="result-container">
712
  <h4>πŸ”¬ μΆ”κ°€ 검사 ꢌμž₯사항 / Recommended Additional Tests</h4>
713
- <ul>
714
- <li>ν”ΌλΆ€ 쑰직검사 (ν•„μš”μ‹œ) / Skin biopsy (if necessary)</li>
715
- <li>μ•Œλ ˆλ₯΄κΈ° 검사 / Allergy testing</li>
716
- <li>ν˜ˆμ•‘ 검사 / Blood tests</li>
717
- <li>μ§„κ·  λ°°μ–‘ 검사 (감염 μ˜μ‹¬μ‹œ) / Fungal culture (if infection suspected)</li>
718
- </ul>
719
  </div>
720
  </div>
721
  """
722
 
723
  return analysis
724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
  def _translate_disease_name(self, disease_name: str) -> str:
726
  """Translate disease name to Korean if not in database."""
727
  # Common translations for diseases not in main database
 
657
  top_class = next(iter(class_probs))
658
  top_confidence = class_probs[top_class]
659
 
660
+ # Get disease information from database - check multiple variations
661
+ disease_info = None
662
 
663
+ # Try different case variations to find the disease
664
+ search_keys = [
665
+ top_class.lower(),
666
+ top_class.lower().replace('_', ' '),
667
+ top_class.lower().replace('-', ' '),
668
+ top_class.replace('_', ' ').lower(),
669
+ top_class.replace('-', ' ').lower()
670
+ ]
671
+
672
+ for key in search_keys:
673
+ if key in self.disease_info_db:
674
+ disease_info = self.disease_info_db[key]
675
+ logger.info(f"Found disease info for: {key}")
676
+ break
677
+
678
+ # If still not found, create comprehensive default information
679
  if disease_info is None:
680
+ logger.warning(f"No database entry for: {top_class}")
681
+ disease_info = self._create_default_disease_info(top_class)
 
 
 
 
682
 
683
+ # Get detailed symptoms if available
684
+ symptoms_text = disease_info.get('symptoms_ko', '')
685
+ if symptoms_text:
686
+ symptoms_html = f"""
687
+ <div class="result-container">
688
+ <h4>πŸ” μ£Όμš” 증상 / Key Symptoms</h4>
689
+ <p>{symptoms_text}</p>
690
+ </div>
691
+ """
692
+ else:
693
+ symptoms_html = ""
694
+
695
+ # Create comprehensive GPT analysis with all available information
696
  analysis = f"""
697
  <div class="diagnosis-card">
698
  <h3>πŸ€– GPT-OSS 상세 뢄석 / GPT-OSS Detailed Analysis</h3>
699
 
700
  <div class="info-box">
701
+ <h4>πŸ“‹ μ§„λ‹¨λœ μ§ˆν™˜ 정보 / Diagnosed Condition Information</h4>
702
+ <p><strong>μ§ˆν™˜λͺ… / Disease:</strong> {top_class.title()} ({disease_info['name_ko']})</p>
703
  <p><strong>신뒰도 / Confidence:</strong> {top_confidence:.1%}</p>
704
+ <p><strong>쀑증도 / Severity:</strong> {self._get_severity_badge(disease_info.get('severity', 'unknown'))}</p>
705
  </div>
706
 
707
+ <div class="result-container">
708
+ <h4>πŸ“– μ§ˆν™˜ μ„€λͺ… / Disease Description</h4>
709
+ <p><strong>{disease_info['name_ko']} ({top_class.title()})</strong></p>
710
+ <p>{disease_info['description_ko']}</p>
711
+ </div>
712
+
713
+ {symptoms_html}
714
+
715
  <div class="result-container">
716
  <h4>πŸ“ ꢌμž₯ μΉ˜λ£Œλ²• / Recommended Treatment</h4>
717
+ <p><strong>치료 방법:</strong></p>
718
+ <p>{disease_info['treatment_ko']}</p>
719
  </div>
720
 
721
  <div class="result-container">
722
  <h4>πŸ’Š μƒν™œ 관리 μ§€μΉ¨ / Lifestyle Management Guidelines</h4>
723
+ {self._get_lifestyle_guidelines(top_class, disease_info.get('severity', 'low'))}
 
 
 
 
 
 
724
  </div>
725
 
726
  <div class="result-container">
727
  <h4>πŸ₯ μ˜λ£Œμ§„ 상담 ν•„μš” μ‹œμ  / When to Consult Healthcare Provider</h4>
728
+ {self._get_consultation_guidelines(disease_info.get('severity', 'low'))}
 
 
 
 
 
 
729
  </div>
730
 
731
  <div class="result-container">
732
  <h4>πŸ”¬ μΆ”κ°€ 검사 ꢌμž₯사항 / Recommended Additional Tests</h4>
733
+ {self._get_test_recommendations(top_class, disease_info.get('severity', 'low'))}
734
+ </div>
735
+
736
+ <div class="result-container">
737
+ <h4>⚠️ μ£Όμ˜μ‚¬ν•­ / Precautions</h4>
738
+ {self._get_precautions(top_class, disease_info.get('severity', 'low'))}
739
  </div>
740
  </div>
741
  """
742
 
743
  return analysis
744
 
745
+ def _create_default_disease_info(self, disease_name: str) -> Dict:
746
+ """Create default disease information when not in database."""
747
+ # Try to infer information from the disease name
748
+ name_lower = disease_name.lower()
749
+
750
+ # Determine Korean name
751
+ name_ko = self._translate_disease_name(disease_name)
752
+
753
+ # Determine severity
754
+ severity = self._estimate_severity(disease_name)
755
+
756
+ # Create appropriate description based on keywords
757
+ if 'cancer' in name_lower or 'carcinoma' in name_lower or 'melanoma' in name_lower:
758
+ description = f"μ•…μ„± μ’…μ–‘μ˜ κ°€λŠ₯성이 μžˆλŠ” ν”ΌλΆ€ λ³‘λ³€μž…λ‹ˆλ‹€. μ¦‰μ‹œ μ „λ¬Έμ˜ 진단이 ν•„μš”ν•©λ‹ˆλ‹€."
759
+ treatment = "μ¦‰μ‹œ ν”ΌλΆ€κ³Ό λ˜λŠ” μ’…μ–‘ μ „λ¬Έμ˜ 상담, 쑰직검사 ν•„μš”, μ‘°κΈ° 진단과 μΉ˜λ£Œκ°€ μ€‘μš”"
760
+ elif 'infection' in name_lower or 'bacterial' in name_lower:
761
+ description = f"μ„Έκ·  감염이 μ˜μ‹¬λ˜λŠ” ν”ΌλΆ€ μ§ˆν™˜μž…λ‹ˆλ‹€. μ μ ˆν•œ ν•­μƒμ œ μΉ˜λ£Œκ°€ ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€."
762
+ treatment = "ν•­μƒμ œ 치료(κ΅­μ†Œ λ˜λŠ” 경ꡬ), μƒμ²˜ μ†Œλ…, μœ„μƒ 관리"
763
+ elif 'fungal' in name_lower:
764
+ description = f"μ§„κ·  감염이 μ˜μ‹¬λ˜λŠ” ν”ΌλΆ€ μ§ˆν™˜μž…λ‹ˆλ‹€."
765
+ treatment = "ν•­μ§„κ· μ œ 치료, ν™˜λΆ€ 건쑰 μœ μ§€, 톡풍 κ°œμ„ "
766
+ elif 'dermatitis' in name_lower or 'eczema' in name_lower:
767
+ description = f"ν”ΌλΆ€μ˜ 염증성 μ§ˆν™˜μœΌλ‘œ, 가렀움과 발적이 λ™λ°˜λ  수 μžˆμŠ΅λ‹ˆλ‹€."
768
+ treatment = "보슡제 μ‚¬μš©, κ΅­μ†Œ μŠ€ν…Œλ‘œμ΄λ“œ, ν•­νžˆμŠ€νƒ€λ―Όμ œ, 자극 물질 νšŒν”Ό"
769
+ elif 'acne' in name_lower or 'pimple' in name_lower:
770
+ description = f"λͺ¨λ‚­κ³Ό ν”Όμ§€μ„ μ˜ 염증성 μ§ˆν™˜μž…λ‹ˆλ‹€."
771
+ treatment = "μ μ ˆν•œ ν΄λ Œμ§•, κ΅­μ†Œ 치료제(λ ˆν‹°λ…Έμ΄λ“œ, 벀쑰일 퍼μ˜₯μ‚¬μ΄λ“œ), ν•­μƒμ œ"
772
+ else:
773
+ description = f"ν”ΌλΆ€ μ§ˆν™˜μœΌλ‘œ μ •ν™•ν•œ 진단을 μœ„ν•΄ μ „λ¬Έμ˜ 상담이 ꢌμž₯λ©λ‹ˆλ‹€."
774
+ treatment = "ν”ΌλΆ€κ³Ό μ „λ¬Έμ˜ 상담을 ν†΅ν•œ μ •ν™•ν•œ 진단 ν›„ μ μ ˆν•œ 치료"
775
+
776
+ return {
777
+ "name_ko": name_ko,
778
+ "severity": severity,
779
+ "description_ko": description,
780
+ "treatment_ko": treatment,
781
+ "symptoms_ko": "μœ‘μ•ˆ 검사와 μΆ”κ°€ 검사λ₯Ό 톡해 μ •ν™•ν•œ 증상 νŒŒμ•… ν•„μš”"
782
+ }
783
+
784
+ def _get_severity_badge(self, severity: str) -> str:
785
+ """Get HTML badge for severity level."""
786
+ badges = {
787
+ "none": '<span class="diagnosis-severity">정상 / Normal</span>',
788
+ "low": '<span class="diagnosis-severity severity-low">경증 / Mild</span>',
789
+ "medium": '<span class="diagnosis-severity severity-medium">쀑등도 / Moderate</span>',
790
+ "high": '<span class="diagnosis-severity severity-high">쀑증 / Severe</span>',
791
+ "unknown": '<span class="diagnosis-severity">λ―ΈλΆ„λ₯˜ / Unclassified</span>'
792
+ }
793
+ return badges.get(severity, badges["unknown"])
794
+
795
+ def _get_lifestyle_guidelines(self, disease: str, severity: str) -> str:
796
+ """Get lifestyle management guidelines based on disease and severity."""
797
+ guidelines = "<ul>"
798
+
799
+ # General guidelines for all conditions
800
+ guidelines += "<li>μΆ©λΆ„ν•œ μˆ˜λΆ„ μ„­μ·¨ (ν•˜λ£¨ 8μž” 이상) / Drink plenty of water (8+ glasses daily)</li>"
801
+ guidelines += "<li>κ· ν˜• 작힌 식단 μœ μ§€ / Maintain a balanced diet</li>"
802
+ guidelines += "<li>μΆ©λΆ„ν•œ 수면 (7-8μ‹œκ°„) / Get adequate sleep (7-8 hours)</li>"
803
+
804
+ # Specific guidelines based on disease type
805
+ disease_lower = disease.lower()
806
+
807
+ if 'acne' in disease_lower or 'pimple' in disease_lower:
808
+ guidelines += "<li>μ €μžκ·Ήμ„± ν΄λ Œμ € μ‚¬μš© / Use gentle, non-comedogenic cleanser</li>"
809
+ guidelines += "<li>μ†μœΌλ‘œ μ–Όκ΅΄ λ§Œμ§€μ§€ μ•ŠκΈ° / Avoid touching face with hands</li>"
810
+ guidelines += "<li>μœ μ œν’ˆκ³Ό κ³ λ‹ΉλΆ„ μ‹ν’ˆ μ œν•œ / Limit dairy and high-sugar foods</li>"
811
+
812
+ if 'eczema' in disease_lower or 'dermatitis' in disease_lower:
813
+ guidelines += "<li>ν•˜λ£¨ 2회 이상 보슡제 μ‚¬μš© / Apply moisturizer at least twice daily</li>"
814
+ guidelines += "<li>뜨거운 λ¬Ό μƒ€μ›Œ ν”Όν•˜κΈ° / Avoid hot water showers</li>"
815
+ guidelines += "<li>λ©΄ μ†Œμž¬ 의λ₯˜ 착용 / Wear cotton clothing</li>"
816
+
817
+ if 'psoriasis' in disease_lower:
818
+ guidelines += "<li>슀트레슀 관리 (μš”κ°€, λͺ…상) / Manage stress (yoga, meditation)</li>"
819
+ guidelines += "<li>μ•Œμ½”μ˜¬ μ„­μ·¨ μ œν•œ / Limit alcohol consumption</li>"
820
+ guidelines += "<li>μ μ ˆν•œ ν–‡λΉ› λ…ΈμΆœ / Moderate sun exposure</li>"
821
+
822
+ if severity == "high":
823
+ guidelines += "<li>μ¦‰μ‹œ μ „λ¬Έμ˜ 상담 μ˜ˆμ•½ / Schedule immediate specialist consultation</li>"
824
+ guidelines += "<li>처방된 μ•½λ¬Ό κ·œμΉ™μ  볡용 / Take prescribed medications regularly</li>"
825
+
826
+ guidelines += "<li>μžμ™Έμ„  μ°¨λ‹¨μ œ 맀일 μ‚¬μš© (SPF 30+) / Apply sunscreen daily (SPF 30+)</li>"
827
+ guidelines += "</ul>"
828
+
829
+ return guidelines
830
+
831
+ def _get_consultation_guidelines(self, severity: str) -> str:
832
+ """Get consultation guidelines based on severity."""
833
+ guidelines = "<ul>"
834
+
835
+ if severity == "high":
836
+ guidelines += "<li><strong style='color: red;'>μ¦‰μ‹œ μ˜λ£Œμ§„ 상담 ν•„μš” / Immediate medical consultation required</strong></li>"
837
+ guidelines += "<li>24μ‹œκ°„ 이내 ν”ΌλΆ€κ³Ό λ°©λ¬Έ ꢌμž₯ / Visit dermatologist within 24 hours</li>"
838
+
839
+ guidelines += "<li>증상이 2μ£Ό 이상 지속될 경우 / If symptoms persist for more than 2 weeks</li>"
840
+ guidelines += "<li>톡증, 좜혈, 뢄비물이 μžˆμ„ 경우 / If pain, bleeding, or discharge occurs</li>"
841
+ guidelines += "<li>병변이 κΈ‰μ†νžˆ ν™•μ‚°λ˜λŠ” 경우 / If lesions spread rapidly</li>"
842
+ guidelines += "<li>λ°œμ—΄, μ˜€ν•œ λ“± μ „μ‹  증상 λ™λ°˜ μ‹œ / If accompanied by fever or chills</li>"
843
+ guidelines += "<li>μΌμƒμƒν™œμ— μ§€μž₯을 쀄 μ •λ„λ‘œ μ‹¬ν•œ 경우 / If severe enough to affect daily life</li>"
844
+ guidelines += "<li>κΈ°μ‘΄ μΉ˜λ£Œμ— λ°˜μ‘ν•˜μ§€ μ•ŠλŠ” 경우 / If not responding to current treatment</li>"
845
+ guidelines += "</ul>"
846
+
847
+ return guidelines
848
+
849
+ def _get_test_recommendations(self, disease: str, severity: str) -> str:
850
+ """Get test recommendations based on disease type."""
851
+ tests = "<ul>"
852
+
853
+ disease_lower = disease.lower()
854
+
855
+ # Cancer-related tests
856
+ if 'cancer' in disease_lower or 'carcinoma' in disease_lower or 'melanoma' in disease_lower:
857
+ tests += "<li>ν”ΌλΆ€ 쑰직검사 (Biopsy) - <strong>ν•„μˆ˜</strong></li>"
858
+ tests += "<li>더λͺ¨μŠ€μ½”ν”Ό 검사 / Dermoscopy examination</li>"
859
+ tests += "<li>μ „μ‹  ν”ΌλΆ€ κ²€μ§„ / Full body skin examination</li>"
860
+ tests += "<li>λ¦Όν”„μ ˆ 검사 / Lymph node examination</li>"
861
+
862
+ # Infection tests
863
+ elif 'infection' in disease_lower or 'bacterial' in disease_lower or 'fungal' in disease_lower:
864
+ tests += "<li>μ„Έκ·  λ°°μ–‘ 검사 / Bacterial culture</li>"
865
+ tests += "<li>μ§„κ·  검사 (KOH test) / Fungal examination</li>"
866
+ tests += "<li>ν•­μƒμ œ κ°μˆ˜μ„± 검사 / Antibiotic sensitivity test</li>"
867
+
868
+ # Allergy/Dermatitis tests
869
+ elif 'dermatitis' in disease_lower or 'eczema' in disease_lower:
870
+ tests += "<li>패치 ν…ŒμŠ€νŠΈ (μ•Œλ ˆλ₯΄κΈ° 검사) / Patch testing</li>"
871
+ tests += "<li>ν˜ˆμ•‘ IgE 검사 / Blood IgE test</li>"
872
+ tests += "<li>ν”ΌλΆ€ λ‹¨μž 검사 / Skin prick test</li>"
873
+
874
+ # General tests
875
+ else:
876
+ tests += "<li>ν”ΌλΆ€ ν™•λŒ€κ²½ 검사 / Magnified skin examination</li>"
877
+ tests += "<li>Wood's lamp 검사 (ν•„μš”μ‹œ) / Wood's lamp examination (if needed)</li>"
878
+
879
+ if severity == "high":
880
+ tests += "<li>ν˜ˆμ•‘ 검사 (CBC, CRP) / Blood tests (CBC, CRP)</li>"
881
+ tests += "<li>μ˜μƒ 검사 (ν•„μš”μ‹œ) / Imaging studies (if needed)</li>"
882
+
883
+ tests += "</ul>"
884
+
885
+ return tests
886
+
887
+ def _get_precautions(self, disease: str, severity: str) -> str:
888
+ """Get precautions based on disease type."""
889
+ precautions = "<ul>"
890
+
891
+ if severity == "high":
892
+ precautions += "<li><strong>μžκ°€ 치료 κΈˆμ§€ - λ°˜λ“œμ‹œ μ „λ¬Έμ˜ 상담</strong></li>"
893
+
894
+ precautions += "<li>처방 없이 μŠ€ν…Œλ‘œμ΄λ“œ μ—°κ³  μž₯κΈ° μ‚¬μš© κΈˆμ§€ / Avoid long-term steroid use without prescription</li>"
895
+ precautions += "<li>병변 λΆ€μœ„ κΈκ±°λ‚˜ μžκ·Ήν•˜μ§€ μ•ŠκΈ° / Do not scratch or irritate affected areas</li>"
896
+ precautions += "<li>κ²€μ¦λ˜μ§€ μ•Šμ€ λ―Όκ°„μš”λ²• ν”Όν•˜κΈ° / Avoid unverified home remedies</li>"
897
+ precautions += "<li>타인과 수건, 의λ₯˜ 곡유 κΈˆμ§€ / Do not share towels or clothing</li>"
898
+ precautions += "<li>증상 μ•…ν™” μ‹œ μ¦‰μ‹œ μ˜λ£Œμ§„ 상담 / Consult immediately if symptoms worsen</li>"
899
+ precautions += "</ul>"
900
+
901
+ return precautions
902
+
903
  def _translate_disease_name(self, disease_name: str) -> str:
904
  """Translate disease name to Korean if not in database."""
905
  # Common translations for diseases not in main database