@@ -180,8 +180,11 @@ def call_llm_detailed_plotly_schema(self, scenario: str, id: int, suffix: str):
180180
181181 return id , True
182182
183- def call_llm_python_code (self , scenario : str , id : int , prompt : str = "" , theme : str = "" , number_of_charts : int = 3 ):
184- default_prompt = "Represent the visualization as {number_of_charts} different suitable chart types using Plotly Express. Choose the chart types that best fit the data and scenario."
183+ def call_llm_python_code (self , scenario : str , id : int , prompt : str = "" , theme : str = "" , chartType : str = "" , number_of_charts : int = 1 ):
184+ introductory_prompt = "Create Python code using Plotly Express to generate visualizations for the following scenario."
185+ if chartType != "" :
186+ introductory_prompt = f"Create Python code using Plotly Express to generate visualizations of type '{ chartType } ' for the following scenario."
187+ default_prompt = f"Represent the visualization strictly as { number_of_charts } 'scatterpolar' chart types using Plotly Express. Use realistic data to show in the chart."
185188 if prompt == "" :
186189 prompt = default_prompt
187190 messages = [
@@ -191,7 +194,7 @@ def call_llm_python_code(self, scenario: str, id: int, prompt: str = "", theme:
191194 },
192195 {
193196 "role" : "user" ,
194- "content" : f"""Create Python code using Plotly Express to generate visualizations for the following scenario.
197+ "content" : f"""{ introductory_prompt }
195198 Use realistic data to show in the chart.
196199 { prompt }
197200 The Python code should generate the Plotly JSON chart schemas for each visualization.
@@ -279,22 +282,68 @@ def call_llm_locale_plotly_schema(self, scenario: str, id: int, industry:str, la
279282
280283 return id
281284
282-
285+ class Response :
286+ @staticmethod
287+ def model_json_schema ():
288+ return {
289+ "type" : "object" ,
290+ "properties" : {
291+ "scenarios" : {
292+ "type" : "array" ,
293+ "items" : {
294+ "type" : "object" ,
295+ "properties" : {
296+ "industry" : {"type" : "string" },
297+ "scenario_name" : {"type" : "string" },
298+ "scenario_description" : {"type" : "string" },
299+ "columns" : {
300+ "type" : "array" ,
301+ "items" : {"type" : "string" },
302+ "description" : "Key columns required for the scenario."
303+ },
304+ "sources" : {
305+ "type" : "array" ,
306+ "items" : {"type" : "string" },
307+ "description" : "Data sources integrated for the scenario."
308+ },
309+ "aggregation_level" : {
310+ "type" : "string" ,
311+ "description" : "Level of aggregation required for the scenario."
312+ }
313+ },
314+ "required" : [
315+ "industry" ,
316+ "scenario_name" ,
317+ "scenario_description" ,
318+ "columns" ,
319+ "sources" ,
320+ "aggregation_level"
321+ ]
322+ }
323+ }
324+ },
325+ "required" : ["scenarios" ]
326+ }
327+
283328class VisualizationGenerator :
284329 """Generates visualization scenarios, schemas, and codes."""
285330
286331 def __init__ (self , scenario_dir , token_provider ):
287332 self .scenario_dir = scenario_dir
288333 self .llm_client = LLMClient (token_provider )
289334
290- def generate_visualization_scenarios (self , json_data ):
335+ def generate_visualization_scenarios (self , json_data , chart_type = "" ):
291336 response_format = {
292337 'type' : 'json_schema' ,
293338 'json_schema' : {
294339 "name" : "ScenariosSchema" ,
295340 "schema" : Response .model_json_schema ()
296341 }
297342 }
343+ additional_prompt = ""
344+ if chart_type != "" :
345+ additional_prompt = f"specifically for the chart type { chart_type } "
346+ os .makedirs (self .scenario_dir , exist_ok = True )
298347 for industry_data in json_data ['industries' ]:
299348 print (f"Industry: { industry_data ['industry' ]} " )
300349 messages = [
@@ -304,7 +353,7 @@ def generate_visualization_scenarios(self, json_data):
304353 },
305354 {
306355 "role" : "user" ,
307- "content" : f"""Refer to the below example. Generate similar scenarios that need charts to showcase the reports and dashboards for { industry_data ['industry' ]} industry.
356+ "content" : f"""Refer to the below example. Generate similar scenarios that need charts to showcase the reports and dashboards for { industry_data ['industry' ]} industry { additional_prompt } .
308357Provide detailed explanation of each scenario in 10 lines in the description section. Generate the output in a similar JSON structure. Include information like the columns needed, sources of data, aggregation level needed in the report.
309358[START EXAMPLE]
310359{ json .dumps (industry_data )}
@@ -347,7 +396,8 @@ def generate_visualization_codes(self):
347396
348397 for scenario_data in json_data .get ('scenarios' , []):
349398 print (f"Industry: { scenario_data ['industry' ]} , Scenario: { scenario_data ['scenario_name' ]} " )
350- id = self .llm_client .call_llm_python_code (json .dumps (scenario_data ), id )
399+ prompt = "Generate python code for that would generate plotly schemas for scatterpolar chart having modes 'markers'."
400+ id = self .llm_client .call_llm_python_code (json .dumps (scenario_data ), id , prompt , theme = '' , chartType = 'scatterpolar' , number_of_charts = 3 )
351401
352402 def generate_visualization_python_code_colors (self ):
353403 if not os .path .exists (self .scenario_dir ):
@@ -376,7 +426,7 @@ def generate_visualization_python_code_colors(self):
376426 prompt += f"Use { theme } color theme for the charts."
377427 for scenario_data in json_data .get ('scenarios' , []):
378428 print (f"Industry: { scenario_data ['industry' ]} , Scenario: { scenario_data ['scenario_name' ]} , Theme: { theme } " )
379- id = self .llm_client .call_llm_python_code (json .dumps (scenario_data ), id , prompt , theme , 1 )
429+ id = self .llm_client .call_llm_python_code (json .dumps (scenario_data ), id , prompt , theme , '' , 1 )
380430 break
381431
382432 def generate_detailed_visualization_schemas (self ):
@@ -500,12 +550,16 @@ def get_chart_type_from_image(self):
500550 DefaultAzureCredential (),
501551 "https://cognitiveservices.azure.com/.default"
502552 )
503- scenario_dir = 'detailed_scenarios'
504-
553+ # scenario_dir = 'detailed_scenarios'
554+ scenario_dir = "scatterpolar_chart_scenarios"
505555 # Generate visualizations
506556 visualization_generator = VisualizationGenerator (scenario_dir , token_provider )
507- # visualization_generator.generate_visualization_codes()
508- visualization_generator .generate_visualization_python_code_colors ()
557+ visualization_generator .generate_visualization_scenarios (
558+ json_data = FileManager .read_json_file ('scenarios.json' ),
559+ chart_type = "scatterpolar"
560+ )
561+ visualization_generator .generate_visualization_codes ()
562+ # visualization_generator.generate_visualization_python_code_colors()
509563
510564 # Generate chart types from images
511565 # chart_type_generator = ChartTypeGenerator(token_provider)
0 commit comments