|
1 | | -from AI.main import call_openai_model, classify_image |
2 | 1 | import os |
3 | 2 | import sys |
4 | 3 | from flask import Flask, request, jsonify |
5 | 4 | import uuid |
6 | 5 | import cv2 |
7 | 6 |
|
| 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 | + |
8 | 18 | current_dir = os.path.dirname(os.path.abspath(__file__)) |
9 | 19 | parent_dir = os.path.dirname(current_dir) |
10 | 20 | if parent_dir not in sys.path: |
@@ -65,16 +75,23 @@ def translate(): |
65 | 75 | if image_opencv is None: |
66 | 76 | return jsonify({'error': f'Could not read image: {filename}'}), 400 |
67 | 77 |
|
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) |
70 | 86 |
|
71 | 87 | os.remove(file_path) |
72 | 88 |
|
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) |
75 | 92 |
|
76 | 93 | return jsonify({ |
77 | | - 'translation': final_translation.content |
| 94 | + # 'translation': final_translation.content |
78 | 95 | }), 200 |
79 | 96 |
|
80 | 97 | if __name__ == '__main__': |
|
0 commit comments