Spaces:
Paused
Paused
Commit
•
b9a27ee
1
Parent(s):
c4f0a69
integrated celery
Browse files
README.md
CHANGED
@@ -26,6 +26,12 @@ Additionally, it handles various word forms and multi-term descriptions to maint
|
|
26 |
|
27 |
## Running
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
```
|
30 |
docker build -t brightly-ai .
|
31 |
docker run -p 7860:7860 brightly-ai
|
|
|
26 |
|
27 |
## Running
|
28 |
|
29 |
+
```
|
30 |
+
# Start celery worker
|
31 |
+
celery -A tasks worker --loglevel=info
|
32 |
+
python run.py
|
33 |
+
```
|
34 |
+
|
35 |
```
|
36 |
docker build -t brightly-ai .
|
37 |
docker run -p 7860:7860 brightly-ai
|
algo.py
CHANGED
@@ -13,8 +13,10 @@ from db.db_utils import store_mapping_to_db, cached_get_mapping_from_db, get_dic
|
|
13 |
from ask_gpt import query_gpt
|
14 |
from multi_food_item_detector import extract_items, has_delimiters
|
15 |
from mapping_template import empty_template
|
|
|
16 |
|
17 |
-
|
|
|
18 |
similarity_threshold = 0.75
|
19 |
|
20 |
|
@@ -385,7 +387,9 @@ class Algo:
|
|
385 |
mapping.update({
|
386 |
'run_row': input_row_num
|
387 |
})
|
388 |
-
|
389 |
-
|
|
|
|
|
390 |
|
391 |
return results
|
|
|
13 |
from ask_gpt import query_gpt
|
14 |
from multi_food_item_detector import extract_items, has_delimiters
|
15 |
from mapping_template import empty_template
|
16 |
+
from tasks import insert_result_async
|
17 |
|
18 |
+
|
19 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
20 |
similarity_threshold = 0.75
|
21 |
|
22 |
|
|
|
387 |
mapping.update({
|
388 |
'run_row': input_row_num
|
389 |
})
|
390 |
+
insert_result_async.delay(self.run_key, mapping)
|
391 |
+
# TODO: push this to celery queue
|
392 |
+
# results.append(mapping)
|
393 |
+
# store_result_to_db(self.db_cursor, self.db_conn, self.run_key, mapping)
|
394 |
|
395 |
return results
|
requirements.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
autocorrect==2.6.1
|
|
|
3 |
gradio==4.36.1
|
4 |
mistralai==0.4.0
|
5 |
numpy==1.26.4
|
@@ -10,6 +11,7 @@ psutil==6.0.0
|
|
10 |
psycopg2-binary==2.9.9
|
11 |
python-dotenv==1.0.1
|
12 |
python-Levenshtein==0.25.1
|
|
|
13 |
requests==2.32.3
|
14 |
sentence_transformers==3.0.1
|
15 |
spacy==3.7.5
|
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
autocorrect==2.6.1
|
3 |
+
celery==5.4.0
|
4 |
gradio==4.36.1
|
5 |
mistralai==0.4.0
|
6 |
numpy==1.26.4
|
|
|
11 |
psycopg2-binary==2.9.9
|
12 |
python-dotenv==1.0.1
|
13 |
python-Levenshtein==0.25.1
|
14 |
+
redis==5.0.7
|
15 |
requests==2.32.3
|
16 |
sentence_transformers==3.0.1
|
17 |
spacy==3.7.5
|
tasks.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# tasks.py
|
2 |
+
import logging
|
3 |
+
from celery import Celery
|
4 |
+
from db.db_utils import get_connection, store_result_to_db
|
5 |
+
|
6 |
+
|
7 |
+
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
|
8 |
+
|
9 |
+
app.conf.update(
|
10 |
+
result_expires=3600,
|
11 |
+
task_serializer='json',
|
12 |
+
result_serializer='json',
|
13 |
+
accept_content=['json'],
|
14 |
+
timezone='UTC',
|
15 |
+
enable_utc=True,
|
16 |
+
)
|
17 |
+
|
18 |
+
@app.task
|
19 |
+
def insert_result_async(run_key, mapping):
|
20 |
+
logging.info(f"Inserting result for run_key: {run_key}, mapping: {mapping['input_word']}")
|
21 |
+
db_conn = get_connection()
|
22 |
+
db_cursor = db_conn.cursor()
|
23 |
+
store_result_to_db(db_cursor, db_conn, run_key, mapping)
|
24 |
+
db_conn.close()
|