Inference.
Browse files
app/api/api_v1/endpoints/openai.py
CHANGED
|
@@ -43,25 +43,6 @@ PIL.Image.MAX_IMAGE_PIXELS = None
|
|
| 43 |
router = APIRouter()
|
| 44 |
embeddings = OpenAIEmbeddings()
|
| 45 |
|
| 46 |
-
def retry_with_backoff(retries = 5, backoff_in_seconds = 1):
|
| 47 |
-
def rwb(f):
|
| 48 |
-
def wrapper(*args, **kwargs):
|
| 49 |
-
x = 0
|
| 50 |
-
while True:
|
| 51 |
-
try:
|
| 52 |
-
return f(*args, **kwargs)
|
| 53 |
-
except:
|
| 54 |
-
if x == retries:
|
| 55 |
-
raise
|
| 56 |
-
|
| 57 |
-
sleep = (backoff_in_seconds * 2 ** x +
|
| 58 |
-
random.uniform(0, 1))
|
| 59 |
-
time.sleep(sleep)
|
| 60 |
-
x += 1
|
| 61 |
-
|
| 62 |
-
return wrapper
|
| 63 |
-
return rwb
|
| 64 |
-
|
| 65 |
def convert_from_ls(result):
|
| 66 |
if 'original_width' not in result or 'original_height' not in result:
|
| 67 |
return None
|
|
@@ -86,14 +67,6 @@ def embed_documents(collection: CollectionStore):
|
|
| 86 |
pre_delete_embeddings=True
|
| 87 |
)
|
| 88 |
|
| 89 |
-
@retry_with_backoff(retries=6)
|
| 90 |
-
def export_tasks(task_id, tmp_archive):
|
| 91 |
-
label_studio_project.export_tasks("COCO", False, True, [task_id], tmp_archive)
|
| 92 |
-
|
| 93 |
-
@retry_with_backoff(retries=6)
|
| 94 |
-
def import_tasks(tmp_file):
|
| 95 |
-
return label_studio_project.import_tasks(tmp_file)
|
| 96 |
-
|
| 97 |
def embed(db: Session, payload: schemas.LabelStudio):
|
| 98 |
|
| 99 |
task_id = payload.task["id"]
|
|
@@ -112,7 +85,7 @@ def embed(db: Session, payload: schemas.LabelStudio):
|
|
| 112 |
|
| 113 |
notebook_dir = "{}/notebooks".format(tmp_dir)
|
| 114 |
|
| 115 |
-
export_tasks(task_id, tmp_archive)
|
| 116 |
|
| 117 |
with zipfile.ZipFile(tmp_archive, 'r') as zip_ref:
|
| 118 |
zip_ref.extractall(tmp_dir)
|
|
@@ -207,7 +180,7 @@ async def create_collection(
|
|
| 207 |
target_height = round(height - (height * 0.75))
|
| 208 |
cover = cover.resize((target_width, target_height), PIL.Image.Resampling.LANCZOS)
|
| 209 |
cover.save(tmp_file, optimize=True, quality=95)
|
| 210 |
-
tasks = import_tasks(tmp_file)
|
| 211 |
os.remove(tmp_file)
|
| 212 |
|
| 213 |
|
|
|
|
| 43 |
router = APIRouter()
|
| 44 |
embeddings = OpenAIEmbeddings()
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def convert_from_ls(result):
|
| 47 |
if 'original_width' not in result or 'original_height' not in result:
|
| 48 |
return None
|
|
|
|
| 67 |
pre_delete_embeddings=True
|
| 68 |
)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def embed(db: Session, payload: schemas.LabelStudio):
|
| 71 |
|
| 72 |
task_id = payload.task["id"]
|
|
|
|
| 85 |
|
| 86 |
notebook_dir = "{}/notebooks".format(tmp_dir)
|
| 87 |
|
| 88 |
+
label_studio_project.export_tasks("COCO", False, True, [task_id], tmp_archive)
|
| 89 |
|
| 90 |
with zipfile.ZipFile(tmp_archive, 'r') as zip_ref:
|
| 91 |
zip_ref.extractall(tmp_dir)
|
|
|
|
| 180 |
target_height = round(height - (height * 0.75))
|
| 181 |
cover = cover.resize((target_width, target_height), PIL.Image.Resampling.LANCZOS)
|
| 182 |
cover.save(tmp_file, optimize=True, quality=95)
|
| 183 |
+
tasks = label_studio_project.import_tasks(tmp_file)
|
| 184 |
os.remove(tmp_file)
|
| 185 |
|
| 186 |
|