Spaces:
Build error
Build error
Create setup.py
Browse files
setup.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer
|
| 4 |
+
from huggingface_hub import snapshot_download
|
| 5 |
+
|
| 6 |
+
# Define environment variables
|
| 7 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers_cache"
|
| 8 |
+
os.environ["HF_HOME"] = "/tmp/hf_home"
|
| 9 |
+
|
| 10 |
+
# Define model options - use smaller models for Spaces deployment
|
| 11 |
+
ASR_OPTIONS = {
|
| 12 |
+
"Whisper Small": "openai/whisper-small",
|
| 13 |
+
"Wav2Vec2": "facebook/wav2vec2-base-960h"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
LLM_OPTIONS = {
|
| 17 |
+
"Llama-2 7B Chat": "meta-llama/Llama-2-7b-chat-hf",
|
| 18 |
+
"Flan-T5 Small": "google/flan-t5-small"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
TTS_OPTIONS = {
|
| 22 |
+
"VITS": "espnet/kan-bayashi_ljspeech_vits",
|
| 23 |
+
"FastSpeech2": "espnet/kan-bayashi_ljspeech_fastspeech2"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
def preload_models():
|
| 27 |
+
"""
|
| 28 |
+
Preload essential components to optimize startup time
|
| 29 |
+
"""
|
| 30 |
+
print("Setting up model environment...")
|
| 31 |
+
|
| 32 |
+
# Check for GPU availability
|
| 33 |
+
if torch.cuda.is_available():
|
| 34 |
+
print(f"GPU available: {torch.cuda.get_device_name(0)}")
|
| 35 |
+
print(f"Memory available: {torch.cuda.get_device_properties(0).total_memory / 1e9:.2f} GB")
|
| 36 |
+
else:
|
| 37 |
+
print("No GPU available. Running in CPU mode (performance will be limited).")
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
# Download tokenizers first (smaller files)
|
| 41 |
+
for model_name, model_id in LLM_OPTIONS.items():
|
| 42 |
+
print(f"Downloading tokenizer for {model_name}...")
|
| 43 |
+
AutoTokenizer.from_pretrained(model_id)
|
| 44 |
+
|
| 45 |
+
# We don't preload the full models - they'll be loaded on-demand
|
| 46 |
+
print("Environment setup complete!")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"Setup error: {e}")
|
| 49 |
+
print("The application will still attempt to run, but might experience delays.")
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
preload_models()
|