Felladrin commited on
Commit
783645d
·
1 Parent(s): 320038e

Add Docker Compose setup and simplify environment configuration

Browse files
Files changed (7) hide show
  1. .env.example +1 -0
  2. .gitignore +1 -3
  3. Dockerfile +1 -1
  4. README.md +24 -40
  5. app.py +1 -1
  6. docker-compose.yml +7 -0
  7. run.sh +0 -3
.env.example ADDED
@@ -0,0 +1 @@
 
 
1
+ HF_TOKEN=
.gitignore CHANGED
@@ -1,3 +1 @@
1
- .venv
2
- .streamlit
3
- transformers.js
 
1
+ .env
 
 
Dockerfile CHANGED
@@ -24,6 +24,6 @@ RUN pip install --no-cache-dir -U pip \
24
 
25
  COPY . .
26
 
27
- EXPOSE 8501
28
 
29
  CMD ["sh", "-c", "streamlit run app.py --server.port $PORT --server.address 0.0.0.0"]
 
24
 
25
  COPY . .
26
 
27
+ EXPOSE $PORT
28
 
29
  CMD ["sh", "-c", "streamlit run app.py --server.port $PORT --server.address 0.0.0.0"]
README.md CHANGED
@@ -14,60 +14,44 @@ short_description: Convert a Hugging Face model to ONNX format
14
 
15
  ## Overview
16
 
17
- This project provides a Streamlit application that converts Hugging Face models to ONNX (Open Neural Network Exchange) format, enabling broader model compatibility and deployment options. The application streamlines the process of downloading, converting, and uploading models to Hugging Face.
18
 
19
- ## Features
20
 
21
- - **One-Click Model Conversion**: Convert Hugging Face models to ONNX format with minimal configuration
22
- - **User-Friendly Interface**: Intuitive Streamlit-based web interface
23
- - **Quantization Support**: Automatic model quantization for reduced size and faster inference
24
 
25
- ## Prerequisites
26
 
27
- - Python 3.8+
28
- - Hugging Face account and API token
29
- - Git
30
 
31
- ## Installation
32
 
33
- 1. Clone the repository:
 
 
34
 
35
- ```bash
36
- git clone https://huggingface.co/spaces/onnx-community/convert-to-onnx
37
- cd convert-to-onnx
38
- ```
39
 
40
- 2. Install dependencies:
41
 
42
- ```bash
43
- pip install -r requirements.txt
44
- ```
45
 
46
- 3. Configure Hugging Face credentials:
47
 
48
- ```bash
49
- # Option 1: Environment variables
50
- export HF_TOKEN="your_token"
51
 
52
- # Option 2: Create .streamlit/secrets.toml
53
- echo 'HF_TOKEN = "your_token"' > .streamlit/secrets.toml
54
- ```
55
 
56
- ## Usage
 
57
 
58
- 1. Start the application:
59
-
60
- ```bash
61
- streamlit run app.py
62
- ```
63
-
64
- 2. Access the web interface at `http://localhost:8501`
65
-
66
- 3. Enter a Hugging Face model ID (e.g., `EleutherAI/pythia-14m`)
67
-
68
- 4. Click "Proceed" to start the conversion
69
-
70
- The converted model will be available in your Hugging Face account as `{username}/{model-name}-ONNX`.
71
 
72
  ## Development
73
 
 
14
 
15
  ## Overview
16
 
17
+ This project provides a Streamlit application that facilitates the conversion of Hugging Face models to ONNX format, downloading, converting, and uploading models to Hugging Face.
18
 
19
+ ## Docker Compose usage
20
 
21
+ ### 1. Prepare environment variables
 
 
22
 
23
+ Copy the provided template and fill in your Hugging Face write token:
24
 
25
+ ```bash
26
+ cp .env.example .env
27
+ ```
28
 
29
+ ### 2. Start the application
30
 
31
+ ```bash
32
+ docker compose up
33
+ ```
34
 
35
+ Access the interface at `http://localhost:8501`.
 
 
 
36
 
37
+ Enter a Hugging Face model ID (e.g., `EleutherAI/pythia-14m`).
38
 
39
+ After a successful conversion, the ONNX export is available under `{username}/{model-name}-ONNX` unless you opt into reusing the same repository.
 
 
40
 
41
+ To stop the service, press `Ctrl+C` (or run `docker compose down`). Add `-d` to run detached.
42
 
43
+ ## Direct Docker usage (optional)
 
 
44
 
45
+ If you prefer not to use Docker Compose, you can still build and run manually:
 
 
46
 
47
+ ```bash
48
+ docker build -t convert-to-onnx .
49
 
50
+ docker run --rm \
51
+ -p 8501:8501 \
52
+ -e HF_TOKEN="your_write_token" \
53
+ convert-to-onnx
54
+ ```
 
 
 
 
 
 
 
 
55
 
56
  ## Development
57
 
app.py CHANGED
@@ -27,7 +27,7 @@ class Config:
27
  @classmethod
28
  def from_env(cls) -> "Config":
29
  """Create config from environment variables and secrets."""
30
- system_token = os.getenv("HF_TOKEN") or st.secrets.get("HF_TOKEN")
31
  user_token = st.session_state.get("user_hf_token")
32
 
33
  if user_token:
 
27
  @classmethod
28
  def from_env(cls) -> "Config":
29
  """Create config from environment variables and secrets."""
30
+ system_token = os.getenv("HF_TOKEN")
31
  user_token = st.session_state.get("user_hf_token")
32
 
33
  if user_token:
docker-compose.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ services:
2
+ app:
3
+ build: .
4
+ ports:
5
+ - "8501:8501"
6
+ environment:
7
+ - HF_TOKEN=${HF_TOKEN}
run.sh DELETED
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
- pip install -r requirements.txt
3
- streamlit run app.py