Pujan Neupane commited on
Commit ·
d762de0
1
Parent(s): 7098c2e
Updated: UPDATED README.md as well as some changes in code and url
Browse files38 unmodified lines39404142434445464748495051522 unmodified lines5556575859606162636465666768697071727374757677787936 unmodified lines1161171181191201211221231241251261271282 unmodified lines13113213313413513613713841 unmodified lines18018118218318418518618793 unmodified lines28128228328428528628738 unmodified lines### **Code Overview**```pythonexecutor = ThreadPoolExecutor(max_workers=2)```- **`ThreadPoolExecutor(max_workers=2)`** limits the number of concurrent threads (tasks) per worker process to 2 for text classification. This helps control resource usage and prevent overloading the server.---### **Running and Load Balancing:**To run the app in production with load balancing:2 unmodified linesuvicorn app:app --host 0.0.0.0 --port 8000 --workers 4```This command launches the FastAPI app with **4 worker processes**, allowing it to handle multiple requests concurrently.### **Concurrency Explained:**1. **`ThreadPoolExecutor(max_workers=20)`**- Controls the **number of threads** within a **single worker** process.- Allows up to 20 tasks (text classification requests) to be handled simultaneously per worker, improving responsiveness for I/O-bound tasks.2. **`--workers 4` in Uvicorn**- Spawns **4 independent worker processes** to handle incoming HTTP requests.- Each worker can independently handle multiple tasks, increasing the app's ability to process concurrent requests in parallel.### **How They Relate:**- **Uvicorn’s `--workers`** defines how many worker processes the server will run.- **`ThreadPoolExecutor`** limits how many tasks (threads) each worker can process concurrently.For example, with **4 workers** and **20 threads per worker**, the server can handle **80 tasks concurrently**. This provides scalable and efficient processing, balancing the load across multiple workers and threads.### **Endpoints**36 unmodified linesYou can test the FastAPI endpoint using `curl` like this:```bashcurl -X POST http://127.0.0.1:8000/analyze \-H "Authorization: Bearer HelloThere" \-H "Content-Type: application/json" \-d '{"text": "This is a sample sentence for analysis."}'```- The `-H "Authorization: Bearer HelloThere"` part is used to simulate the **handshake**.- FastAPI checks this token against the one loaded from the `.env` file.- If the token matches, the request is accepted and processed.- Otherwise, it responds with a `403 Unauthorized` error.2 unmodified lines### **API Documentation**- **Swagger UI:** `http://127.0.0.1:8000/docs` -> `/docs`- **ReDoc:** `http://127.0.0.1:8000/redoc` -> `/redoc`### **🔐 Handshake Mechanism**41 unmodified linesCreate a `.env` file at the root with the following:```environmentFASTAPI_BASE_URL=http://localhost:8000SECRET_TOKEN="HelloThere"```#### 2. `fastapi.service.ts`93 unmodified linesMake sure your FastAPI service is running at `http://localhost:8000`.### Test with CURL```bashcurl -X POST http://localhost:3000/analyze-text \-H 'Content-Type: application/json' \38 unmodified lines3940414243442 unmodified lines474849505152535436 unmodified lines9192939495969798991001011021032 unmodified lines10610710810911011111211341 unmodified lines15515615715815916016116293 unmodified lines25625725825926026126238 unmodified lines### **Code Overview**### **Running and Load Balancing:**To run the app in production with load balancing:2 unmodified linesuvicorn app:app --host 0.0.0.0 --port 8000 --workers 4```This command launches the FastAPI app.### **Endpoints**36 unmodified linesYou can test the FastAPI endpoint using `curl` like this:```bashcurl -X POST https://can-org-canspace.hf.space/analyze \-H "Authorization: Bearer SECRET_CODE" \-H "Content-Type: application/json" \-d '{"text": "This is a sample sentence for analysis."}'```- The `-H "Authorization: Bearer SECRET_CODE"` part is used to simulate the **handshake**.- FastAPI checks this token against the one loaded from the `.env` file.- If the token matches, the request is accepted and processed.- Otherwise, it responds with a `403 Unauthorized` error.2 unmodified lines### **API Documentation**- **Swagger UI:** `https://can-org-canspace.hf.space/docs` -> `/docs`- **ReDoc:** `https://can-org-canspace.hf.space/redoc` -> `/redoc`### **🔐 Handshake Mechanism**41 unmodified linesCreate a `.env` file at the root with the following:```environmentFASTAPI_BASE_URL=https://can-org-canspace.hf.space/SECRET_TOKEN="SECRET_CODE_TOKEN"```#### 2. `fastapi.service.ts`93 unmodified linesMake sure your FastAPI service is running at `http://localhost:8000`.### Test with CURLhttp://localhost:3000/-> Server of nest.js```bashcurl -X POST http://localhost:3000/analyze-text \-H 'Content-Type: application/json' \
README.md+9-34