Skip to content

Commit 6dab83f

Browse files
imported ai module to use the model + use the model from hugging face fot translations
1 parent 5a98f75 commit 6dab83f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

backend/server.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
from AI.main import call_openai_model, classify_image
21
import os
32
import sys
43
from flask import Flask, request, jsonify
54
import uuid
65
import cv2
76

7+
import importlib.util
8+
import sys
9+
from pathlib import Path
10+
11+
module_path = Path(__file__).resolve().parent.parent / 'AI' / 'main.py'
12+
13+
spec = importlib.util.spec_from_file_location("ai", module_path)
14+
ai = importlib.util.module_from_spec(spec)
15+
sys.modules["ai"] = ai
16+
spec.loader.exec_module(ai)
17+
818
current_dir = os.path.dirname(os.path.abspath(__file__))
919
parent_dir = os.path.dirname(current_dir)
1020
if parent_dir not in sys.path:
@@ -65,16 +75,23 @@ def translate():
6575
if image_opencv is None:
6676
return jsonify({'error': f'Could not read image: {filename}'}), 400
6777

68-
translation_result = classify_image(image_opencv)
69-
all_translations.append(translation_result)
78+
translation_result = ai.classify_image_huggingface(image_opencv)
79+
print(translation_result)
80+
81+
# translation_result = ai.classify_image(image_opencv)
82+
# if translation_result:
83+
# all_translations.append(translation_result[0][0].category_name)
84+
# if translation_result:
85+
# print(translation_result[0][0].category_name)
7086

7187
os.remove(file_path)
7288

73-
translation_string = ' '.join(all_translations)
74-
final_translation = call_openai_model(translation_string)
89+
# translation_string = ' '.join(all_translations)
90+
# final_translation = ai.call_openai_model(translation_string)
91+
# print(final_translation.content)
7592

7693
return jsonify({
77-
'translation': final_translation.content
94+
# 'translation': final_translation.content
7895
}), 200
7996

8097
if __name__ == '__main__':

0 commit comments

Comments
 (0)