Arafath10 commited on
Commit
e782b03
1 Parent(s): 3dfe7ef

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -3
main.py CHANGED
@@ -61,12 +61,25 @@ async def get_image_for_text(email,query,file: UploadFile = File(...)):
61
  else:
62
  return {"error": "Unsupported file type"}
63
 
 
 
 
 
 
 
 
 
 
 
 
64
  try:
65
- sdf = SmartDataframe(df, config={"llm": llm})
66
- sdf.chat(query)
67
- print(df.head())
 
68
  image_path = "exports/charts/temp_chart.png" # Replace with your image's path
69
  base64str = convert_image_to_base64(image_path)
 
70
  return {"id":str(uuid1),"image":base64str}
71
  except Exception as e:
72
  print(str(e))
 
61
  else:
62
  return {"error": "Unsupported file type"}
63
 
64
+ sdf = SmartDataframe(df, config={"llm": llm})
65
+ sdf.chat(query)
66
+
67
+ code_to_exec = """
68
+ import matplotlib.pyplot as plt
69
+ import seaborn as sns\n"""
70
+ code_to_exec = code_to_exec + sdf.last_code_generated.replace("dfs[0]","dfs")
71
+ code_to_exec = code_to_exec.replace("/content/exports/charts/temp_chart.png",email+file_name+".png")
72
+ print(code_to_exec)
73
+ local_vars = {'dfs': df}
74
+ exec(code_to_exec, globals(), local_vars)
75
  try:
76
+
77
+ print(email+file_name+".png",df.head())
78
+
79
+ return FileResponse(email+file_name+".png")
80
  image_path = "exports/charts/temp_chart.png" # Replace with your image's path
81
  base64str = convert_image_to_base64(image_path)
82
+
83
  return {"id":str(uuid1),"image":base64str}
84
  except Exception as e:
85
  print(str(e))