1515from pathlib import Path
1616import boto3
1717import mlrun
18+ import tempfile
1819
1920from src .calls_analysis .db_management import create_tables
2021from src .common import ProjectSecrets
@@ -36,15 +37,15 @@ def setup(
3637 openai_key = os .getenv (ProjectSecrets .OPENAI_API_KEY )
3738 openai_base = os .getenv (ProjectSecrets .OPENAI_API_BASE )
3839 mysql_url = os .getenv (ProjectSecrets .MYSQL_URL , "" )
39-
4040 # Unpack parameters:
4141 source = project .get_param (key = "source" )
42- default_image = project .get_param (key = "default_image" , default = None )
42+ default_image = project .get_param (key = "default_image" , default = ".mlrun-project-image-call-center-demo" )
4343 build_image = project .get_param (key = "build_image" , default = False )
4444 gpus = project .get_param (key = "gpus" , default = 0 )
4545 node_name = project .get_param (key = "node_name" , default = None )
4646 node_selector = project .get_param (key = "node_selector" , default = None )
47- use_sqlite = project .get_param (key = "use_sqlite" , default = False )
47+ use_sqlite = project .get_param (key = "use_sqlite" , default = True )
48+ skip_calls_generation = project .get_param (key = "skip_calls_generation" , default = False )
4849
4950 # Update sqlite data:
5051 if use_sqlite :
@@ -53,15 +54,16 @@ def setup(
5354 s3 = boto3 .client ("s3" ) if not os .getenv ("AWS_ENDPOINT_URL_S3" ) else boto3 .client ('s3' , endpoint_url = os .getenv ("AWS_ENDPOINT_URL_S3" ))
5455 bucket_name = Path (mlrun .mlconf .artifact_path ).parts [1 ]
5556 # Upload the file
56- s3 .upload_file (
57- Filename = "data/sqlite.db" ,
58- Bucket = bucket_name ,
59- Key = "sqlite.db" ,
60- )
57+ if not skip_calls_generation and Path ("./data/sqlite.db" ).exists ():
58+ s3 .upload_file (
59+ Filename = "data/sqlite.db" ,
60+ Bucket = bucket_name ,
61+ Key = "sqlite.db" ,
62+ )
6163 os .environ ["S3_BUCKET_NAME" ] = bucket_name
6264 else :
63- os . environ [ "MYSQL_URL" ] = f"sqlite:/// { os . path . abspath ( '.' ) } /data/sqlite.db"
64- mysql_url = os . environ [ "MYSQL_URL" ]
65+ if not skip_calls_generation and Path ( ". /data/sqlite.db"). exists ():
66+ project . log_artifact ( "sqlite-db" , local_path = "./data/sqlite.db" , upload = True )
6567
6668 # Set the project git source:
6769 if source :
@@ -72,6 +74,7 @@ def setup(
7274 # Set default image:
7375 if default_image :
7476 project .set_default_image (default_image )
77+ print (f"set default image to : { default_image } " )
7578
7679 # Build the image:
7780 if build_image :
@@ -117,11 +120,12 @@ def setup(
117120 ]
118121 app .save ()
119122
120- # Create the DB tables:
121- create_tables ()
123+ # # Create the DB tables:
124+ # create_tables()
122125
123126 # Save and return the project:
124127 project .save ()
128+
125129 return project
126130
127131def _build_image (project : mlrun .projects .MlrunProject , with_gpu : bool , default_image ):
@@ -133,7 +137,8 @@ def _build_image(project: mlrun.projects.MlrunProject, with_gpu: bool, default_i
133137 # Define commands in logical groups while maintaining order
134138 system_commands = [
135139 # Update apt-get to install ffmpeg (support audio file formats):
136- "apt-get update -y && apt-get install ffmpeg -y"
140+ "apt-get update -y && apt-get install ffmpeg -y" ,
141+ "python --version"
137142 ]
138143
139144 infrastructure_requirements = [
@@ -150,16 +155,17 @@ def _build_image(project: mlrun.projects.MlrunProject, with_gpu: bool, default_i
150155 ] if with_gpu else []
151156
152157 other_requirements = [
153- "pip install mlrun langchain==0.2.17 openai==1.58.1 langchain_community==0.2.19 pydub==0.25.1 streamlit==1.28.0 st-annotated-text==4.0.1 spacy==3.7.1 librosa==0.10.1 presidio-anonymizer==2.2.34 presidio-analyzer==2.2.34 nltk==3.8.1 flair==0.13.0 htbuilder==0.6.2" ,
158+ "pip install langchain==0.2.17 openai==1.58.1 langchain_community==0.2.19 pydub==0.25.1 streamlit==1.28.0 st-annotated-text==4.0.1 spacy==3.7.1 librosa==0.10.1 presidio-anonymizer==2.2.34 presidio-analyzer==2.2.34 nltk==3.8.1 flair==0.13.0 htbuilder==0.6.2" ,
154159 "pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.7.1/en_core_web_lg-3.7.1.tar.gz" ,
155160 # "python -m spacy download en_core_web_lg",
156161
157162 "pip install SQLAlchemy==2.0.31 pymysql requests_toolbelt==0.10.1" ,
158163 "pip uninstall -y onnxruntime-gpu onnxruntime" ,
159164 f"pip install { config ['onnx_package' ]} " ,
160- "pip uninstall -y protobuf" ,
161- "pip install protobuf"
162- ]
165+ "pip show protobuf" ,
166+ ]
167+ if not CE_MODE :
168+ other_requirements .extend (["pip uninstall -y protobuf" , "pip install protobuf" , "pip show protobuf" ])
163169
164170 # Combine commands in the required order
165171 commands = (
@@ -179,7 +185,6 @@ def _build_image(project: mlrun.projects.MlrunProject, with_gpu: bool, default_i
179185 overwrite_build_params = True
180186 )
181187
182-
183188def _set_secrets (
184189 project : mlrun .projects .MlrunProject ,
185190 openai_key : str ,
@@ -241,21 +246,23 @@ def _set_function(
241246 if not CE_MODE and apply_auto_mount :
242247 # Apply auto mount:
243248 mlrun_function .apply (mlrun .auto_mount ())
249+
244250 # Save:
245251 mlrun_function .save ()
246252
247253
248254def _set_calls_generation_functions (
249255 project : mlrun .projects .MlrunProject ,
250256 node_name : str = None ,
251- image : str = ".mlrun-project-image"
257+ image : str = ".mlrun-project-image-call-center-demo "
252258):
253259 # Client and agent data generator
254260 _set_function (
255261 project = project ,
256262 func = "hub://structured_data_generator" ,
257263 name = "structured-data-generator" ,
258264 kind = "job" ,
265+ image = image ,
259266 node_name = node_name ,
260267 apply_auto_mount = True ,
261268 )
@@ -355,7 +362,6 @@ def _set_calls_analysis_functions(
355362
356363
357364def _set_workflows (project : mlrun .projects .MlrunProject , image ):
358-
359365 project .set_workflow (
360366 name = "calls-generation" , workflow_path = "./src/workflows/calls_generation.py" , image = image
361367 )
0 commit comments