Spaces:
Build error
Build error
Update project documentation and dependencies to English, modify HuggingFace model initialization
Browse files- README.md +33 -33
- app.py +1 -1
- requirements.txt +3 -2
README.md
CHANGED
|
@@ -11,83 +11,83 @@ short_description: Backend of SmolLM2 chat
|
|
| 11 |
|
| 12 |
# SmolLM2 Backend
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
###
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
1.
|
| 23 |
-
2.
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
|
| 29 |
-
###
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
1.
|
| 34 |
-
2.
|
| 35 |
```
|
| 36 |
-
HUGGINGFACE_TOKEN=
|
| 37 |
```
|
| 38 |
-
3.
|
| 39 |
```
|
| 40 |
pip install -r requirements.txt
|
| 41 |
```
|
| 42 |
|
| 43 |
-
##
|
| 44 |
|
| 45 |
```bash
|
| 46 |
uvicorn app:app --reload
|
| 47 |
```
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
## Endpoints
|
| 52 |
|
| 53 |
-
### GET
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
### POST
|
| 58 |
|
| 59 |
-
Endpoint
|
| 60 |
|
| 61 |
-
**
|
| 62 |
```json
|
| 63 |
{
|
| 64 |
-
"query": "
|
| 65 |
-
"thread_id": "
|
| 66 |
}
|
| 67 |
```
|
| 68 |
|
| 69 |
-
**
|
| 70 |
```json
|
| 71 |
{
|
| 72 |
-
"generated_text": "
|
| 73 |
-
"thread_id": "
|
| 74 |
}
|
| 75 |
```
|
| 76 |
|
| 77 |
## Docker
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
```bash
|
| 82 |
-
#
|
| 83 |
docker build -t smollm2-backend .
|
| 84 |
|
| 85 |
-
#
|
| 86 |
docker run -p 8000:8000 --env-file .env smollm2-backend
|
| 87 |
```
|
| 88 |
|
| 89 |
-
##
|
| 90 |
|
| 91 |
-
|
| 92 |
- Swagger UI: `http://localhost:8000/docs`
|
| 93 |
- ReDoc: `http://localhost:8000/redoc`
|
|
|
|
| 11 |
|
| 12 |
# SmolLM2 Backend
|
| 13 |
|
| 14 |
+
This project implements a FastAPI API that uses LangChain and LangGraph to generate text with the Qwen2.5-72B-Instruct model from HuggingFace.
|
| 15 |
|
| 16 |
+
## Configuration
|
| 17 |
|
| 18 |
+
### In HuggingFace Spaces
|
| 19 |
|
| 20 |
+
This project is designed to run in HuggingFace Spaces. To configure it:
|
| 21 |
|
| 22 |
+
1. Create a new Space in HuggingFace with SDK Docker
|
| 23 |
+
2. Configure the `HUGGINGFACE_TOKEN` or `HF_TOKEN` environment variable in the Space configuration:
|
| 24 |
+
- Go to the "Settings" tab of your Space
|
| 25 |
+
- Scroll down to the "Repository secrets" section
|
| 26 |
+
- Add a new variable with the name `HUGGINGFACE_TOKEN` and your token as the value
|
| 27 |
+
- Save the changes
|
| 28 |
|
| 29 |
+
### Local development
|
| 30 |
|
| 31 |
+
For local development:
|
| 32 |
|
| 33 |
+
1. Clone this repository
|
| 34 |
+
2. Create a `.env` file in the project root with your HuggingFace token:
|
| 35 |
```
|
| 36 |
+
HUGGINGFACE_TOKEN=your_token_here
|
| 37 |
```
|
| 38 |
+
3. Install the dependencies:
|
| 39 |
```
|
| 40 |
pip install -r requirements.txt
|
| 41 |
```
|
| 42 |
|
| 43 |
+
## Local execution
|
| 44 |
|
| 45 |
```bash
|
| 46 |
uvicorn app:app --reload
|
| 47 |
```
|
| 48 |
|
| 49 |
+
The API will be available at `http://localhost:8000`.
|
| 50 |
|
| 51 |
## Endpoints
|
| 52 |
|
| 53 |
+
### GET `/`
|
| 54 |
|
| 55 |
+
Welcome endpoint that returns a greeting message.
|
| 56 |
|
| 57 |
+
### POST `/generate`
|
| 58 |
|
| 59 |
+
Endpoint to generate text using the language model.
|
| 60 |
|
| 61 |
+
**Request parameters:**
|
| 62 |
```json
|
| 63 |
{
|
| 64 |
+
"query": "Your question here",
|
| 65 |
+
"thread_id": "optional_thread_identifier"
|
| 66 |
}
|
| 67 |
```
|
| 68 |
|
| 69 |
+
**Response:**
|
| 70 |
```json
|
| 71 |
{
|
| 72 |
+
"generated_text": "Generated text by the model",
|
| 73 |
+
"thread_id": "thread identifier"
|
| 74 |
}
|
| 75 |
```
|
| 76 |
|
| 77 |
## Docker
|
| 78 |
|
| 79 |
+
To run the application in a Docker container:
|
| 80 |
|
| 81 |
```bash
|
| 82 |
+
# Build the image
|
| 83 |
docker build -t smollm2-backend .
|
| 84 |
|
| 85 |
+
# Run the container
|
| 86 |
docker run -p 8000:8000 --env-file .env smollm2-backend
|
| 87 |
```
|
| 88 |
|
| 89 |
+
## API documentation
|
| 90 |
|
| 91 |
+
The interactive API documentation is available at:
|
| 92 |
- Swagger UI: `http://localhost:8000/docs`
|
| 93 |
- ReDoc: `http://localhost:8000/redoc`
|
app.py
CHANGED
|
@@ -21,7 +21,7 @@ if not HUGGINGFACE_TOKEN:
|
|
| 21 |
|
| 22 |
# Inicializar el modelo
|
| 23 |
model = HuggingFaceEndpoint(
|
| 24 |
-
|
| 25 |
huggingfacehub_api_token=HUGGINGFACE_TOKEN,
|
| 26 |
max_new_tokens=64,
|
| 27 |
temperature=0.5,
|
|
|
|
| 21 |
|
| 22 |
# Inicializar el modelo
|
| 23 |
model = HuggingFaceEndpoint(
|
| 24 |
+
repo_id="Qwen/Qwen2.5-72B-Instruct",
|
| 25 |
huggingfacehub_api_token=HUGGINGFACE_TOKEN,
|
| 26 |
max_new_tokens=64,
|
| 27 |
temperature=0.5,
|
requirements.txt
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
-
fastapi
|
| 2 |
uvicorn
|
| 3 |
requests
|
| 4 |
pydantic>=2.0.0
|
| 5 |
langchain
|
| 6 |
langchain-huggingface
|
| 7 |
-
|
|
|
|
| 8 |
python-dotenv
|
| 9 |
clarifai
|
| 10 |
Pillow
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
uvicorn
|
| 3 |
requests
|
| 4 |
pydantic>=2.0.0
|
| 5 |
langchain
|
| 6 |
langchain-huggingface
|
| 7 |
+
langchain-core
|
| 8 |
+
langgraph > 0.2.27
|
| 9 |
python-dotenv
|
| 10 |
clarifai
|
| 11 |
Pillow
|