nexusbert commited on
Commit
7ae33a4
·
1 Parent(s): bc61487

Add explicit HF_TOKEN support for Hugging Face Spaces

Browse files
README.md CHANGED
@@ -70,6 +70,10 @@ python app.py
70
  - Educational tool for medical students
71
  - Research tool for studying correlation between visual findings and written reports
72
 
 
 
 
 
73
  ## Note
74
 
75
  This system is designed as a support tool and should not replace professional medical diagnosis. Always consult with healthcare professionals for medical decisions.
 
70
  - Educational tool for medical students
71
  - Research tool for studying correlation between visual findings and written reports
72
 
73
+ ## Environment Variables
74
+
75
+ - **HF_TOKEN** (optional): Hugging Face token for accessing private models or improved rate limits. If not set, the system will use public models without authentication.
76
+
77
  ## Note
78
 
79
  This system is designed as a support tool and should not replace professional medical diagnosis. Always consult with healthcare professionals for medical decisions.
mediSync/models/image_analyzer.py CHANGED
@@ -35,9 +35,15 @@ class XRayImageAnalyzer:
35
  self.logger.info(f"Using device: {self.device}")
36
 
37
  # Load model and feature extractor
 
 
38
  try:
39
- self.feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
40
- self.model = AutoModelForImageClassification.from_pretrained(model_name)
 
 
 
 
41
  self.model.to(self.device)
42
  self.model.eval() # Set to evaluation mode
43
  self.logger.info(f"Successfully loaded model: {model_name}")
 
35
  self.logger.info(f"Using device: {self.device}")
36
 
37
  # Load model and feature extractor
38
+ # Use HF_TOKEN from environment if available (for Hugging Face Spaces)
39
+ hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
40
  try:
41
+ self.feature_extractor = AutoFeatureExtractor.from_pretrained(
42
+ model_name, token=hf_token
43
+ )
44
+ self.model = AutoModelForImageClassification.from_pretrained(
45
+ model_name, token=hf_token
46
+ )
47
  self.model.to(self.device)
48
  self.model.eval() # Set to evaluation mode
49
  self.logger.info(f"Successfully loaded model: {model_name}")
mediSync/models/text_analyzer.py CHANGED
@@ -1,4 +1,5 @@
1
  import logging
 
2
  import re
3
 
4
  import torch
@@ -40,6 +41,9 @@ class MedicalReportAnalyzer:
40
 
41
  self.logger.info(f"Using device: {self.device}")
42
 
 
 
 
43
  # Load NER model for entity extraction
44
  try:
45
  self.ner_pipeline = pipeline(
@@ -47,6 +51,7 @@ class MedicalReportAnalyzer:
47
  model=ner_model,
48
  aggregation_strategy="simple",
49
  device=0 if self.device == "cuda" else -1,
 
50
  )
51
  self.logger.info(f"Successfully loaded NER model: {ner_model}")
52
  except Exception as e:
@@ -55,9 +60,11 @@ class MedicalReportAnalyzer:
55
 
56
  # Load classifier model for severity assessment
57
  try:
58
- self.tokenizer = AutoTokenizer.from_pretrained(classifier_model)
 
 
59
  self.classifier = AutoModelForSequenceClassification.from_pretrained(
60
- classifier_model
61
  )
62
  self.classifier.to(self.device)
63
  self.classifier.eval()
 
1
  import logging
2
+ import os
3
  import re
4
 
5
  import torch
 
41
 
42
  self.logger.info(f"Using device: {self.device}")
43
 
44
+ # Use HF_TOKEN from environment if available (for Hugging Face Spaces)
45
+ hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
46
+
47
  # Load NER model for entity extraction
48
  try:
49
  self.ner_pipeline = pipeline(
 
51
  model=ner_model,
52
  aggregation_strategy="simple",
53
  device=0 if self.device == "cuda" else -1,
54
+ token=hf_token,
55
  )
56
  self.logger.info(f"Successfully loaded NER model: {ner_model}")
57
  except Exception as e:
 
60
 
61
  # Load classifier model for severity assessment
62
  try:
63
+ self.tokenizer = AutoTokenizer.from_pretrained(
64
+ classifier_model, token=hf_token
65
+ )
66
  self.classifier = AutoModelForSequenceClassification.from_pretrained(
67
+ classifier_model, token=hf_token
68
  )
69
  self.classifier.to(self.device)
70
  self.classifier.eval()