Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
@@ -4,9 +4,101 @@ emoji: π¬
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.11.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
NLP Model Deployment with FastAPI
|
13 |
+
|
14 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/actions)
|
15 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/actions)
|
16 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/network/updates)
|
17 |
+
[](https://www.python.org/)
|
18 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/blob/main/LICENSE)
|
19 |
+
[](https://codecov.io/gh/Chemically-Motivated-Solutions/NLPToolkit)
|
20 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/releases)
|
21 |
+
[](https://github.com/Chemically-Motivated-Solutions/NLPToolkit/issues)
|
22 |
+
|
23 |
+
Overview
|
24 |
+
This project demonstrates how to deploy Natural Language Processing (NLP) models using FastAPI, a modern web framework for building APIs with Python. The application integrates two pre-trained models from the Hugging Face Transformers library:
|
25 |
+
|
26 |
+
Sequence Classification Model: Utilized for tasks like sentiment analysis.
|
27 |
+
Question Answering Model: Designed to provide answers based on a given context.
|
28 |
+
Features
|
29 |
+
RESTful API Endpoints:
|
30 |
+
|
31 |
+
/predict: Accepts user input and returns model predictions.
|
32 |
+
/health: Provides health status of the API.
|
33 |
+
Model Integration:
|
34 |
+
|
35 |
+
Incorporates Hugging Face's AutoModelForSequenceClassification and AutoModelForQuestionAnswering for NLP tasks.
|
36 |
+
Installation
|
37 |
+
Clone the Repository:
|
38 |
+
|
39 |
+
bash
|
40 |
+
Copy code
|
41 |
+
git clone https://github.com/yourusername/nlp-fastapi-deployment.git
|
42 |
+
cd nlp-fastapi-deployment
|
43 |
+
Set Up a Virtual Environment:
|
44 |
+
|
45 |
+
bash
|
46 |
+
Copy code
|
47 |
+
python -m venv venv
|
48 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
49 |
+
Install Dependencies:
|
50 |
+
|
51 |
+
bash
|
52 |
+
Copy code
|
53 |
+
pip install -r requirements.txt
|
54 |
+
Usage
|
55 |
+
Start the FastAPI Server:
|
56 |
+
|
57 |
+
bash
|
58 |
+
Copy code
|
59 |
+
uvicorn main:app --reload
|
60 |
+
The API will be accessible at http://127.0.0.1:8000.
|
61 |
+
|
62 |
+
Interact with the API:
|
63 |
+
|
64 |
+
Navigate to http://127.0.0.1:8000/docs to access the interactive API documentation provided by Swagger UI.
|
65 |
+
|
66 |
+
**Example Request:**
|
67 |
+
|
68 |
+
```bash
|
69 |
+
curl -X POST "http://127.0.0.1:8000/predict" -H "Content-Type: application/json" -d '{"text": "Your input text here"}'
|
70 |
+
```
|
71 |
+
## Project Structure
|
72 |
+
```plaintext
|
73 |
+
nlp-fastapi-deployment/
|
74 |
+
βββ app/
|
75 |
+
β βββ __init__.py
|
76 |
+
β βββ main.py # Main application file
|
77 |
+
β βββ models.py # Pydantic models for request and response
|
78 |
+
β βββ nlp_models.py # Functions for loading and utilizing NLP models
|
79 |
+
β βββ utils.py # Utility functions
|
80 |
+
βββ requirements.txt # Project dependencies
|
81 |
+
βββ README.md # Project documentation
|
82 |
+
βββ .gitignore # Git ignore file
|
83 |
+
```
|
84 |
+
## Dependencies
|
85 |
+
- FastAPI: Web framework for building APIs with Python.
|
86 |
+
- Transformers: Library for state-of-the-art NLP models.
|
87 |
+
- Torch: Deep learning framework used by Transformers.
|
88 |
+
- Uvicorn: ASGI server for running FastAPI applications.
|
89 |
+
|
90 |
+
**Ensure all dependencies are listed in requirements.txt for easy installation.**
|
91 |
+
|
92 |
+
## Contributing
|
93 |
+
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
|
94 |
+
|
95 |
+
## License
|
96 |
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
97 |
+
|
98 |
+
## Acknowledgements
|
99 |
+
- Hugging Face for providing accessible NLP models.
|
100 |
+
- FastAPI for the high-performance API framework.
|
101 |
+
**For a visual guide on creating a deep learning API with FastAPI, you might find the following resource helpful:**
|
102 |
+
https://youtu.be/NrarIs9n24I
|
103 |
+
|
104 |
+
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|