-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (30 loc) · 1.11 KB
/
main.py
File metadata and controls
39 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from fastapi import FastAPI
import pandas as pd
from fastapi import UploadFile, File
from io import BytesIO
import uvicorn
import seaborn as sns
import matplotlib.pyplot as plt
from fastapi.responses import StreamingResponse
import io
app = FastAPI()
@app.post("/figure")
async def create_figure(file: UploadFile = File(...)):
# Read the uploaded Excel file
contents = await file.read()
excel_data = pd.read_excel(BytesIO(contents))
print(excel_data.head()) # Print the first few rows of the DataFrame for debugging
return {"message": "File received", "filename": file.filename}
# Create a plot (example: correlation heatmap)
# plt.figure(figsize=(10, 8))
# sns.heatmap(excel_data.corr(), annot=True, cmap="coolwarm")
# plt.title("Correlation Heatmap")
# # Save the plot to a BytesIO buffer
# buf = io.BytesIO()
# plt.savefig(buf, format="png")
# buf.seek(0)
# plt.close()
# # Return the plot as a StreamingResponse
# return StreamingResponse(buf, media_type="image/png")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)