Spaces:
Runtime error
Runtime error
Download server.py from yuvarajareddy001/optimized-llm-log-classification: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/yuvarajareddy001/optimized-llm-log-classification/resolve/main/server.py
- Command line
-
hf download hf://spaces/yuvarajareddy001/optimized-llm-log-classification/server.py
-
curl -L -o server.py https://huggingface.co/spaces/yuvarajareddy001/optimized-llm-log-classification/resolve/main/server.py
1.37 kB
| import uvicorn | |
| import pandas as pd | |
| from fastapi import FastAPI, UploadFile, HTTPException | |
| from fastapi.responses import FileResponse | |
| from classify import classify | |
| app = FastAPI() | |
| async def classify_logs(file: UploadFile): | |
| if not file.filename.endswith('.csv'): | |
| raise HTTPException(status_code=400, detail="File must be a CSV.") | |
| try: | |
| # Read the uploaded CSV | |
| df = pd.read_csv(file.file) | |
| if "source" not in df.columns or "log_message" not in df.columns: | |
| raise HTTPException(status_code=400, detail="CSV must contain 'source' and 'log_message' columns.") | |
| # Perform classification | |
| df["target_label"] = classify(list(zip(df["source"], df["log_message"]))) | |
| print("Dataframe:",df.to_dict()) | |
| # Save the modified file | |
| output_file = "resources/output.csv" | |
| df.to_csv(output_file, index=False) | |
| print("File saved to output.csv") | |
| return FileResponse(output_file, media_type='text/csv') | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| finally: | |
| file.file.close() | |
| # # Clean up if the file was saved | |
| # if os.path.exists("output.csv"): | |
| # os.remove("output.csv") | |
| if __name__ == '__main__': | |
| uvicorn.run("server:app", host="127.0.0.1", port=8000, reload=True) |