Arafath10 commited on
Commit
fed63e7
1 Parent(s): 70bb5bd

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -2
main.py CHANGED
@@ -40,12 +40,21 @@ def convert_image_to_base64(image_path):
40
  @app.post("/get_image_for_text")
41
  async def get_image_for_text(email,query,file: UploadFile = File(...)):
42
  print(file.filename)
43
- with open(email+".csv", "wb") as file_object:
 
44
  file_object.write(file.file.read())
45
  uuid1 = uuid.uuid1()
46
  llm = OpenAI(api_token=secret,save_charts=True)
 
 
 
 
 
 
 
 
 
47
  try:
48
- df = pd.read_csv(email+".csv")
49
  sdf = SmartDataframe(df, config={"llm": llm})
50
  sdf.chat(query)
51
  image_path = "exports/charts/temp_chart.png" # Replace with your image's path
 
40
  @app.post("/get_image_for_text")
41
  async def get_image_for_text(email,query,file: UploadFile = File(...)):
42
  print(file.filename)
43
+ file_name = file.filename
44
+ with open(email+file_name, "wb") as file_object:
45
  file_object.write(file.file.read())
46
  uuid1 = uuid.uuid1()
47
  llm = OpenAI(api_token=secret,save_charts=True)
48
+
49
+ # Determine the file type and read accordingly
50
+ if file_name.endswith('.csv'):
51
+ df = pd.read_csv(email+file_name)
52
+ elif file_name.endswith('.xls') or file_name.endswith('.xlsx'):
53
+ df = pd.read_excel(email+file_name)
54
+ else:
55
+ return {"error": "Unsupported file type"}
56
+
57
  try:
 
58
  sdf = SmartDataframe(df, config={"llm": llm})
59
  sdf.chat(query)
60
  image_path = "exports/charts/temp_chart.png" # Replace with your image's path