yomna-ashraf commited on
Commit
76c478c
·
verified ·
1 Parent(s): 167c1f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -3,23 +3,16 @@ from transformers import AutoModelForImageClassification, AutoProcessor
3
  from PIL import Image
4
  import io
5
  import fitz # PyMuPDF
6
- from flask_cors import CORS, cross_origin
7
 
8
  app = Flask(__name__)
9
- CORS(app)
10
 
11
- # Add debugging logs to check the model loading process
12
  model_name = "AsmaaElnagger/Diabetic_RetinoPathy_detection"
 
 
13
 
14
- try:
15
- print("Loading model...")
16
- model = AutoModelForImageClassification.from_pretrained(model_name, cache_dir="/mnt/data") # Specifying the cache dir for Hugging Face Space
17
- processor = AutoProcessor.from_pretrained(model_name, cache_dir="/mnt/data")
18
- print("Model loaded successfully.")
19
- except Exception as e:
20
- print(f"Error loading model: {e}")
21
-
22
- # Function to convert PDF to images
23
  def pdf_to_images_pymupdf(pdf_data):
24
  try:
25
  pdf_document = fitz.open(stream=pdf_data, filetype="pdf")
@@ -35,7 +28,6 @@ def pdf_to_images_pymupdf(pdf_data):
35
  return None
36
 
37
  @app.route('/classify', methods=['POST'])
38
- @cross_origin() # Allows cross-origin requests (important for frontend)
39
  def classify_file():
40
  if 'file' not in request.files:
41
  return jsonify({'error': 'No file provided'}), 400
@@ -79,4 +71,4 @@ def classify_file():
79
  return jsonify({'error': f'An error occurred: {e}'}), 500
80
 
81
  if __name__ == '__main__':
82
- app.run(port=5001, debug=True)
 
3
  from PIL import Image
4
  import io
5
  import fitz # PyMuPDF
6
+ from flask_cors import CORS
7
 
8
  app = Flask(__name__)
9
+ CORS(app) # Allow cross-origin requests
10
 
11
+ # Load model and processor
12
  model_name = "AsmaaElnagger/Diabetic_RetinoPathy_detection"
13
+ model = AutoModelForImageClassification.from_pretrained(model_name)
14
+ processor = AutoProcessor.from_pretrained(model_name)
15
 
 
 
 
 
 
 
 
 
 
16
  def pdf_to_images_pymupdf(pdf_data):
17
  try:
18
  pdf_document = fitz.open(stream=pdf_data, filetype="pdf")
 
28
  return None
29
 
30
  @app.route('/classify', methods=['POST'])
 
31
  def classify_file():
32
  if 'file' not in request.files:
33
  return jsonify({'error': 'No file provided'}), 400
 
71
  return jsonify({'error': f'An error occurred: {e}'}), 500
72
 
73
  if __name__ == '__main__':
74
+ app.run(host="0.0.0.0", port=7860, debug=True) # Make it accessible from any network interface