Maximofn commited on
Commit
5f2f118
1 Parent(s): 016d983

Update project documentation and dependencies to English, modify HuggingFace model initialization

Browse files
Files changed (3) hide show
  1. README.md +33 -33
  2. app.py +1 -1
  3. requirements.txt +3 -2
README.md CHANGED
@@ -11,83 +11,83 @@ short_description: Backend of SmolLM2 chat
11
 
12
  # SmolLM2 Backend
13
 
14
- Este proyecto implementa una API con FastAPI que utiliza LangChain y LangGraph para generar texto con el modelo Qwen2.5-72B-Instruct de HuggingFace.
15
 
16
- ## Configuraci贸n
17
 
18
- ### En HuggingFace Spaces
19
 
20
- Este proyecto est谩 dise帽ado para ejecutarse en HuggingFace Spaces. Para configurarlo:
21
 
22
- 1. Crea un nuevo Space en HuggingFace con SDK Docker
23
- 2. Configura la variable de entorno `HUGGINGFACE_TOKEN` o `HF_TOKEN` en la configuraci贸n del Space:
24
- - Ve a la pesta帽a "Settings" de tu Space
25
- - Despl谩zate hasta la secci贸n "Repository secrets"
26
- - Agrega una nueva variable con el nombre `HUGGINGFACE_TOKEN` y tu token como valor
27
- - Guarda los cambios
28
 
29
- ### Desarrollo local
30
 
31
- Para desarrollo local:
32
 
33
- 1. Clona este repositorio
34
- 2. Crea un archivo `.env` en la ra铆z del proyecto con tu token de HuggingFace:
35
  ```
36
- HUGGINGFACE_TOKEN=tu_token_aqui
37
  ```
38
- 3. Instala las dependencias:
39
  ```
40
  pip install -r requirements.txt
41
  ```
42
 
43
- ## Ejecuci贸n local
44
 
45
  ```bash
46
  uvicorn app:app --reload
47
  ```
48
 
49
- La API estar谩 disponible en `http://localhost:8000`.
50
 
51
  ## Endpoints
52
 
53
- ### GET /
54
 
55
- Endpoint de bienvenida que devuelve un mensaje de saludo.
56
 
57
- ### POST /generate
58
 
59
- Endpoint para generar texto usando el modelo de lenguaje.
60
 
61
- **Par谩metros de la solicitud:**
62
  ```json
63
  {
64
- "query": "Tu pregunta aqu铆",
65
- "thread_id": "identificador_opcional_del_hilo"
66
  }
67
  ```
68
 
69
- **Respuesta:**
70
  ```json
71
  {
72
- "generated_text": "Texto generado por el modelo",
73
- "thread_id": "identificador_del_hilo"
74
  }
75
  ```
76
 
77
  ## Docker
78
 
79
- Para ejecutar la aplicaci贸n en un contenedor Docker:
80
 
81
  ```bash
82
- # Construir la imagen
83
  docker build -t smollm2-backend .
84
 
85
- # Ejecutar el contenedor
86
  docker run -p 8000:8000 --env-file .env smollm2-backend
87
  ```
88
 
89
- ## Documentaci贸n de la API
90
 
91
- La documentaci贸n interactiva de la API est谩 disponible en:
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
- model="Qwen/Qwen2.5-72B-Instruct",
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==0.99.1
2
  uvicorn
3
  requests
4
  pydantic>=2.0.0
5
  langchain
6
  langchain-huggingface
7
- langgraph
 
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