22333Misaka commited on
Commit
8cbe037
·
verified ·
1 Parent(s): d98a7bc

Upload 6 files

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -18
  2. convert_model.py +47 -0
Dockerfile CHANGED
@@ -59,18 +59,12 @@ RUN echo "Downloading model files..." && \
59
  "https://22333misaka-openlist.hf.space/d/od/ref_shantianliang_1.wav" && \
60
  echo "Download complete!"
61
 
 
 
 
62
  # Convert PyTorch models to ONNX
63
  RUN echo "Converting models to ONNX format..." && \
64
- python -c "
65
- import genie_tts as genie
66
- print('Starting ONNX conversion...')
67
- genie.convert_to_onnx(
68
- torch_ckpt_path='/app/temp/model.ckpt',
69
- torch_pth_path='/app/temp/model.pth',
70
- output_dir='/app/models/liang/onnx'
71
- )
72
- print('ONNX conversion complete!')
73
- " && \
74
  echo "Conversion complete!"
75
 
76
  # Clean up temporary files and torch to reduce image size
@@ -78,18 +72,14 @@ RUN rm -rf /app/temp && \
78
  pip uninstall -y torch && \
79
  rm -rf /root/.cache/pip
80
 
81
- # Create model configuration
82
- RUN echo '{\n\
83
- "reference_audio": "reference/audio.wav",\n\
84
- "reference_text": "这是一条参考音频,将此音频拖入参考内,再添加文本,即可合成音色",\n\
85
- "language": "Chinese"\n\
86
- }' > /app/models/liang/config.json
87
 
88
  # Copy application code
89
  COPY app.py .
90
 
91
- # Download Genie base data
92
- RUN python -c "import genie_tts; genie_tts.download_genie_data()"
93
 
94
  # Expose port (Hugging Face Spaces uses 7860)
95
  EXPOSE 7860
 
59
  "https://22333misaka-openlist.hf.space/d/od/ref_shantianliang_1.wav" && \
60
  echo "Download complete!"
61
 
62
+ # Copy conversion script
63
+ COPY convert_model.py .
64
+
65
  # Convert PyTorch models to ONNX
66
  RUN echo "Converting models to ONNX format..." && \
67
+ python convert_model.py && \
 
 
 
 
 
 
 
 
 
68
  echo "Conversion complete!"
69
 
70
  # Clean up temporary files and torch to reduce image size
 
72
  pip uninstall -y torch && \
73
  rm -rf /root/.cache/pip
74
 
75
+ # Copy model configuration
76
+ COPY models/liang/config.json /app/models/liang/config.json
 
 
 
 
77
 
78
  # Copy application code
79
  COPY app.py .
80
 
81
+ # Download Genie base data (uses a script to avoid inline Python issues)
82
+ RUN python -c 'import genie_tts; genie_tts.download_genie_data()'
83
 
84
  # Expose port (Hugging Face Spaces uses 7860)
85
  EXPOSE 7860
convert_model.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Model Conversion Script
4
+ =======================
5
+ This script downloads and converts PyTorch models to ONNX format.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+
11
+ def main():
12
+ print("Starting ONNX conversion...")
13
+
14
+ import genie_tts as genie
15
+
16
+ ckpt_path = os.environ.get("CKPT_PATH", "/app/temp/model.ckpt")
17
+ pth_path = os.environ.get("PTH_PATH", "/app/temp/model.pth")
18
+ output_dir = os.environ.get("OUTPUT_DIR", "/app/models/liang/onnx")
19
+
20
+ print(f"CKPT path: {ckpt_path}")
21
+ print(f"PTH path: {pth_path}")
22
+ print(f"Output dir: {output_dir}")
23
+
24
+ # Check if files exist
25
+ if not os.path.exists(ckpt_path):
26
+ print(f"Error: CKPT file not found: {ckpt_path}")
27
+ sys.exit(1)
28
+
29
+ if not os.path.exists(pth_path):
30
+ print(f"Error: PTH file not found: {pth_path}")
31
+ sys.exit(1)
32
+
33
+ # Create output directory
34
+ os.makedirs(output_dir, exist_ok=True)
35
+
36
+ # Convert model
37
+ genie.convert_to_onnx(
38
+ torch_ckpt_path=ckpt_path,
39
+ torch_pth_path=pth_path,
40
+ output_dir=output_dir
41
+ )
42
+
43
+ print("ONNX conversion complete!")
44
+
45
+
46
+ if __name__ == "__main__":
47
+ main()