Arafath10 commited on
Commit
d92c861
1 Parent(s): 1da15b7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -0
main.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.responses import StreamingResponse
4
+ from fastapi.responses import FileResponse
5
+ from fastapi.middleware.cors import CORSMiddleware
6
+ import pandas as pd
7
+ from io import StringIO
8
+ import os
9
+
10
+ from pandasai import SmartDataframe
11
+ import pandas as pd
12
+ from pandasai.llm import OpenAI
13
+
14
+
15
+ secret = os.environ["key"]
16
+
17
+ app = FastAPI()
18
+ app.add_middleware(
19
+ CORSMiddleware,
20
+ allow_origins=["*"],
21
+ allow_credentials=True,
22
+ allow_methods=["*"],
23
+ allow_headers=["*"],
24
+ )
25
+
26
+ @app.post("/get_image_for_text")
27
+ async def get_image_for_text(email,query,file: UploadFile = File(...)):
28
+ print(file.filename)
29
+ with open(email+".csv", "wb") as file_object:
30
+ file_object.write(file.file.read())
31
+ llm = OpenAI(api_token=secret,save_charts=True)
32
+ df = pd.read_csv(email+".csv")
33
+ sdf = SmartDataframe(df, config={"llm": llm})
34
+ sdf.chat(query)
35
+ image_path = "exports/charts/temp_chart.png" # Replace with your image's path
36
+ return FileResponse(image_path)