44import uuid
55import cv2
66
7- # adaug directorul parinte in calea de cautare a modulului, pentru a putea importa
8- # PARTEA COMENTATA MOMENTAN NU FUNCTIONEAZA
97current_dir = os .path .dirname (os .path .abspath (__file__ ))
108parent_dir = os .path .dirname (current_dir )
119if parent_dir not in sys .path :
1210 sys .path .insert (0 , parent_dir )
1311from AI .main import classify_image
1412app = Flask (__name__ )
15- # setez directorul in care voi incarca pozele primite de camera din aplicatia flutter.
13+
1614UPLOAD_FOLDER = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'uploads' )
1715app .config ['UPLOAD_FOLDER' ] = UPLOAD_FOLDER
1816app .config ['ALLOWED_EXTENSIONS' ] = ['jpg' , 'png' , 'jpeg' ]
1917
20- # functie pentru a verifica extensia fisierului
2118def check_filename (filename ):
2219 return '.' in filename and filename .rsplit ('.' , 1 )[1 ].lower () in app .config ['ALLOWED_EXTENSIONS' ]
2320
24- @app .route ('/' )
25- def home ():
26- return "Serverul Flask good, good!"
27-
28- # adaug si o ruta de reset, cu rol de a sterge toate fisierele din folderul uploads
29- # va fi folosita de fiecare data cand apas din aplicatia flutter pe butonul Start Translation, pentru
30- # a incepe o noua sesiune de translare a imaginilor de catre modelul AI.
31- @app .route ('/reset' , methods = ['POST' ])
3221def reset_uploads ():
3322 for filename in os .listdir (UPLOAD_FOLDER ):
3423 file_path = os .path .join (UPLOAD_FOLDER , filename )
3524 os .remove (file_path )
36- return "Uploads folder had been reseted!" , 200
25+
3726
38- # aceasta ruta merge, e testata cu PostMan, si uploadeaza si file-ul in folder.
3927@app .route ('/upload' , methods = ['POST' ])
4028def upload_file ():
4129 # verific daca in cerere exista un fisier.
4230 if 'file' not in request .files :
4331 return jsonify ({'error' : 'No file part' }), 400
4432
45- # preiau FISIERUL din request.
4633 file = request .files ['file' ]
4734
4835 if file .filename == '' :
@@ -62,7 +49,6 @@ def upload_file():
6249 else :
6350 return jsonify ({'error' : 'File type not allowed' }), 400
6451
65- # testata si ea cu postman.
6652# Ruta de procesare a imaginii, se asteapta sa primeasca o cerere de genul:
6753# {
6854# "filename": "image_name.jpg"
@@ -74,7 +60,7 @@ def upload_file():
7460# "result_llm": [],
7561# "message": "Image processed successfully"
7662# }
77- @app .route ('/processing_translate' , methods = ['POST ' ])
63+ @app .route ('/processing_translate' , methods = ['GET ' ])
7864def procesing_translate ():
7965 data = request .json
8066 if not data or 'filename' not in data :
@@ -86,13 +72,11 @@ def procesing_translate():
8672 if not os .path .exists (file_path ):
8773 return jsonify ({'error' : 'File not found' }), 404
8874
89- # incarc imaginea si o citesc
9075 image_opencv = cv2 .imread (file_path )
9176 if image_opencv is None :
9277 return jsonify ({'error' : 'Could not read the image' }), 400
9378
9479 # result_huggingface = classify_image_huggingface(image_opencv)
95- # apelez functia din main.py de la llm.
9680 result_llm = classify_image (image_opencv )
9781 return jsonify ({
9882 'message' : 'Image processed successfully' ,
0 commit comments