Update main.py
Browse files
main.py
CHANGED
|
@@ -2,7 +2,6 @@ from fastapi import FastAPI, UploadFile, File
|
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
import pandas as pd
|
| 4 |
import io
|
| 5 |
-
import requests
|
| 6 |
import time
|
| 7 |
|
| 8 |
app = FastAPI()
|
|
@@ -45,6 +44,15 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 45 |
cum_perc=lambda df: df['perc'].cumsum(),
|
| 46 |
)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
result = (
|
| 49 |
"<h1>Redundant IP Requests....</h1>"
|
| 50 |
"<p>The Total API Requests from the sample logs are : {total_requests}</p>"
|
|
@@ -55,17 +63,7 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 55 |
total_requests=logs_df.shape[0],
|
| 56 |
redundant_requests=ip_address_count_df.shape[0],
|
| 57 |
redundant_percentage=(ip_address_count_df.shape[0] / logs_df.shape[0]) * 100,
|
| 58 |
-
|
| 59 |
-
ip_address_count_df.head(1000)
|
| 60 |
-
.style.background_gradient(subset=['count', 'perc', 'cum_perc'], cmap='cividis')
|
| 61 |
-
.format({'count': '{:,}', 'perc': '{:.1%}', 'cum_perc': '{:.1%}'})
|
| 62 |
-
.render()
|
| 63 |
-
.replace('\n', '') # Remove newline characters to format the HTML properly
|
| 64 |
-
)
|
| 65 |
)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
# with open("result.html", "w") as f:
|
| 69 |
-
# f.write(result)
|
| 70 |
-
|
| 71 |
-
return result
|
|
|
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
import pandas as pd
|
| 4 |
import io
|
|
|
|
| 5 |
import time
|
| 6 |
|
| 7 |
app = FastAPI()
|
|
|
|
| 44 |
cum_perc=lambda df: df['perc'].cumsum(),
|
| 45 |
)
|
| 46 |
|
| 47 |
+
dataframe_styled = (
|
| 48 |
+
ip_address_count_df.head(1000)
|
| 49 |
+
.style.background_gradient(subset=['count', 'perc', 'cum_perc'], cmap='cividis')
|
| 50 |
+
.format({'count': '{:,}', 'perc': '{:.1%}', 'cum_perc': '{:.1%}'})
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# Render the styled DataFrame to HTML
|
| 54 |
+
styled_html = dataframe_styled.render()
|
| 55 |
+
|
| 56 |
result = (
|
| 57 |
"<h1>Redundant IP Requests....</h1>"
|
| 58 |
"<p>The Total API Requests from the sample logs are : {total_requests}</p>"
|
|
|
|
| 63 |
total_requests=logs_df.shape[0],
|
| 64 |
redundant_requests=ip_address_count_df.shape[0],
|
| 65 |
redundant_percentage=(ip_address_count_df.shape[0] / logs_df.shape[0]) * 100,
|
| 66 |
+
dataframe_html=styled_html,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
+
return HTMLResponse(content=result)
|
|
|
|
|
|
|
|
|
|
|
|