Skip to content

Commit

Permalink
fix: Watsonx logging (#602)
Browse files Browse the repository at this point in the history
Co-authored-by: Micaela Kaplan <kaplan.micaela@gmail.coml>
  • Loading branch information
micaelakaplan and Micaela Kaplan committed Aug 12, 2024
1 parent 4dc3b99 commit e943934
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions label_studio_ml/examples/watsonx_llm/data_transfer_app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import csv
import logging
import os
import prestodb
import traceback
from flask import Flask, request, jsonify, Response
from label_studio_sdk.client import LabelStudio
from typing import List

logger = logging.getLogger(__name__)
_server = Flask(__name__)


Expand Down Expand Up @@ -62,29 +59,29 @@ def upload_to_watsonx():
# upload new annotation to watsonx
values = tuple([data[key] for key in table_info_keys])
insert_command = f"""INSERT INTO {table} VALUES {values}"""
logger.debug(insert_command)
_server.logger.debug(insert_command)
cur.execute(insert_command)

elif action == "ANNOTATION_UPDATED":
# update existing annotation in watsonx by deleting the old one and uploading a new one
delete = f"""DELETE from {table} WHERE ID={data["ID"]}"""
logger.debug(delete)
_server.logger.debug(delete)
cur.execute(delete)
values = tuple([data[key] for key in table_info_keys])
insert_command = f"""INSERT INTO {table} VALUES {values}"""
logger.debugint(insert_command)
_server.logger.debugint(insert_command)
cur.execute(insert_command)

elif action == "ANNOTATIONS_DELETED":
# delete existing annotation in watsonx
delete = f"""DELETE from {table} WHERE ID={data["ID"]}"""
logger.debug(delete)
_server.logger.debug(delete)
cur.execute(delete)

conn.commit()
except Exception as e:
logger.debug(traceback.format_exc())
logger.debug(e)
_server.logger.debug(traceback.format_exc())
_server.logger.debug(e)


def connect_ls():
Expand All @@ -104,8 +101,8 @@ def connect_ls():
return client

except Exception as e:
logger.debug(traceback.format_exc())
logger.debug(e)
_server.logger.debug(traceback.format_exc())
_server.logger.debug(e)


def get_data(annotation, task, client):
Expand All @@ -131,7 +128,7 @@ def get_data(annotation, task, client):
info.update({key: value})

for result in annotation["result"]:
logger.debug(result)
_server.logger.debug(result)
val_dict_key = list(result["value"].keys())[0]
value = result["value"][val_dict_key]
key = result["from_name"]
Expand All @@ -144,11 +141,11 @@ def get_data(annotation, task, client):
value = value.strip("\"")
info.update({key: value})

logger.debug(f"INFO {info}")
_server.logger.debug(f"INFO {info}")
return info
except Exception as e:
logger.debug(traceback.format_exc())
logger.debug(e)
_server.logger.debug(traceback.format_exc())
_server.logger.debug(e)


def create_table(table, data):
Expand All @@ -170,5 +167,5 @@ def create_table(table, data):
CREATE TABLE IF NOT EXISTS {table} ({nl.join(strings)})
"""
logger.debug(table_create)
_server.logger.debug(table_create)
return table_create, table_info_keys

0 comments on commit e943934

Please sign in to comment.