Update app.py
Browse files
app.py
CHANGED
|
@@ -17,54 +17,102 @@ logger = logging.getLogger(__name__)
|
|
| 17 |
# Tambahkan 'hf_model_name' jika nama model di Hugging Face berbeda dari ID yang Anda inginkan.
|
| 18 |
# Jika nama model di Hugging Face sama, tidak perlu 'hf_model_name'.
|
| 19 |
model_info = {
|
| 20 |
-
"Albert-Base-V2": {
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
"GPT-2
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
"
|
| 29 |
-
"GPT-Neo": {"task": "text-generation", "description": "GPT-Neo model"},
|
| 30 |
-
"Distil-GPT-2": {"task": "text-generation", "description": "Distilled GPT-2 model"},
|
| 31 |
-
# --- MODEL EXTERNAL ---
|
| 32 |
-
"TinyLLama-NSFW-Chatbot": {
|
| 33 |
"task": "text-generation",
|
| 34 |
-
"description": "
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
},
|
| 37 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"task": "text-generation",
|
| 39 |
-
"description": "
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
},
|
| 42 |
-
"
|
| 43 |
"task": "text-generation",
|
| 44 |
-
"description": "
|
| 45 |
-
"hf_model_name": "mistralai/Devstral-Small-2505"
|
| 46 |
},
|
| 47 |
-
"
|
| 48 |
"task": "text-generation",
|
| 49 |
-
"description": "
|
| 50 |
-
"hf_model_name": "nvidia/Llama-3_3-Nemotron-Super-49B-GenRM-Multilingual"
|
| 51 |
},
|
| 52 |
-
|
|
|
|
| 53 |
"task": "text-generation",
|
| 54 |
-
"description": "
|
| 55 |
-
"hf_model_name": "
|
| 56 |
},
|
| 57 |
"whisper-large-v3": {
|
| 58 |
"task": "automatic-speech-recognition",
|
| 59 |
"description": "openai whisper-large-v3",
|
| 60 |
"hf_model_name": "openai/whisper-large-v3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
-
# ---
|
| 65 |
models = {}
|
| 66 |
|
| 67 |
-
# ---
|
| 68 |
def get_model_pipeline(model_name):
|
| 69 |
"""
|
| 70 |
Memuat model hanya jika belum dimuat (lazy loading).
|
|
@@ -78,15 +126,14 @@ def get_model_pipeline(model_name):
|
|
| 78 |
|
| 79 |
info = model_info[model_name]
|
| 80 |
try:
|
| 81 |
-
|
| 82 |
hf_model_path = info.get("hf_model_name", f"Lyon28/{model_name}")
|
| 83 |
|
| 84 |
-
# Explicitly set device to "cpu" for CPU-only environments
|
| 85 |
models[model_name] = pipeline(
|
| 86 |
info["task"],
|
| 87 |
model=hf_model_path,
|
| 88 |
-
device="cpu",
|
| 89 |
-
torch_dtype=torch.float32
|
| 90 |
)
|
| 91 |
logger.info(f"✅ Model '{model_name}' (Path: {hf_model_path}) berhasil dimuat.")
|
| 92 |
except Exception as e:
|
|
@@ -224,4 +271,4 @@ if __name__ == '__main__':
|
|
| 224 |
# Untuk Hugging Face Spaces, port biasanya 7860
|
| 225 |
# Menggunakan HOST dari environment variable jika tersedia, default ke 0.0.0.0
|
| 226 |
# Debug=False untuk produksi
|
| 227 |
-
app.run(host=os.getenv('HOST', '0.0.0.0'), port=int(os.getenv('PORT', 7860)), debug=False)
|
|
|
|
| 17 |
# Tambahkan 'hf_model_name' jika nama model di Hugging Face berbeda dari ID yang Anda inginkan.
|
| 18 |
# Jika nama model di Hugging Face sama, tidak perlu 'hf_model_name'.
|
| 19 |
model_info = {
|
| 20 |
+
"Albert-Base-V2": {
|
| 21 |
+
"task": "fill-mask",
|
| 22 |
+
"description": "Lyon28 Albert-Base-V2"
|
| 23 |
+
},
|
| 24 |
+
"GPT-2": {
|
| 25 |
+
"task": "text-generation",
|
| 26 |
+
"description": "Lyon28 GPT-2"
|
| 27 |
+
},
|
| 28 |
+
"Tinny-Llama": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"task": "text-generation",
|
| 30 |
+
"description": "Lyon 28 Tinny Llama"
|
| 31 |
+
},
|
| 32 |
+
"Electra-Small": {
|
| 33 |
+
"task": "fill-mask",
|
| 34 |
+
"description": "Lyon28 Small ELECTRA"
|
| 35 |
+
},
|
| 36 |
+
"GPT-2-Tinny": {
|
| 37 |
+
"task": "text-generation",
|
| 38 |
+
"description": "Lyon28 Tiny GPT-2"
|
| 39 |
+
},
|
| 40 |
+
"Bert-Tinny": {
|
| 41 |
+
"task": "fill-mask",
|
| 42 |
+
"description": "Lyon28 Tiny BERT"
|
| 43 |
},
|
| 44 |
+
"Distilbert-Base-Uncased": {
|
| 45 |
+
"task": "fill-mask",
|
| 46 |
+
"description": "Lyon28 Distilled BERT"
|
| 47 |
+
},
|
| 48 |
+
"Pythia": {
|
| 49 |
"task": "text-generation",
|
| 50 |
+
"description": "Lyon28 Pythia"
|
| 51 |
+
},
|
| 52 |
+
"T5-Small": {
|
| 53 |
+
"task": "text2text-generation",
|
| 54 |
+
"description": "Lyon28 Small T5"
|
| 55 |
},
|
| 56 |
+
"GPT-Neo": {
|
| 57 |
"task": "text-generation",
|
| 58 |
+
"description": "Lyon28 GPT-Neo"
|
|
|
|
| 59 |
},
|
| 60 |
+
"Distil-GPT-2": {
|
| 61 |
"task": "text-generation",
|
| 62 |
+
"description": "Lyon28 Distilled GPT-2"
|
|
|
|
| 63 |
},
|
| 64 |
+
# --- MODEL EXTERNAL ---
|
| 65 |
+
"TinyLLama-NSFW-Chatbot": {
|
| 66 |
"task": "text-generation",
|
| 67 |
+
"description": "BilalRahib's TinyLLama NSFW Chatbot",
|
| 68 |
+
"hf_model_name": "bilalRahib/TinyLLama-NSFW-Chatbot"
|
| 69 |
},
|
| 70 |
"whisper-large-v3": {
|
| 71 |
"task": "automatic-speech-recognition",
|
| 72 |
"description": "openai whisper-large-v3",
|
| 73 |
"hf_model_name": "openai/whisper-large-v3"
|
| 74 |
+
},
|
| 75 |
+
"Nusantara-4b-Indo-Chat": {
|
| 76 |
+
"task": "text-generation",
|
| 77 |
+
"description": "kalisai Nusantara-4b-Indo-Chat",
|
| 78 |
+
"hf_model_name": "kalisai/Nusantara-4b-Indo-Chat"
|
| 79 |
+
},
|
| 80 |
+
"cendol-llama2-7b-inst": {
|
| 81 |
+
"task": "text-generation",
|
| 82 |
+
"description": "indonlp cendol-llama2-7b-inst",
|
| 83 |
+
"hf_model_name": "indonlp/cendol-llama2-7b-inst"
|
| 84 |
+
},
|
| 85 |
+
"harry-potter-gpt2": {
|
| 86 |
+
"task": "text-generation",
|
| 87 |
+
"description": "akahana harry-potter-gpt2",
|
| 88 |
+
"hf_model_name": "akahana/harry-potter-gpt2"
|
| 89 |
+
},
|
| 90 |
+
"Mistral-7B-Sunda-v1.0": {
|
| 91 |
+
"task": "text-generation",
|
| 92 |
+
"description": "Nero10578 Mistral-7B-Sunda-v1.0",
|
| 93 |
+
"hf_model_name": "Nero10578/Mistral-7B-Sunda-v1.0"
|
| 94 |
+
},
|
| 95 |
+
"gpt2-indo-textgen": {
|
| 96 |
+
"task": "text-generation",
|
| 97 |
+
"description": "anugrahap gpt2-indo-textgen",
|
| 98 |
+
"hf_model_name": "anugrahap/gpt2-indo-textgen"
|
| 99 |
+
},
|
| 100 |
+
"cendol-mt5-small-inst": {
|
| 101 |
+
"task": "text-generation",
|
| 102 |
+
"description": "indonlp cendol-mt5-small-inst",
|
| 103 |
+
"hf_model_name": "indonlp/cendol-mt5-small-inst"
|
| 104 |
+
},
|
| 105 |
+
"madlad400-8b-lm": {
|
| 106 |
+
"task": "text-generation",
|
| 107 |
+
"description": "google madlad400-8b-lm",
|
| 108 |
+
"hf_model_name": "google/madlad400-8b-lm"
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
| 112 |
+
# --- Lazy Loading ---
|
| 113 |
models = {}
|
| 114 |
|
| 115 |
+
# --- Utility Lazy Loading ---
|
| 116 |
def get_model_pipeline(model_name):
|
| 117 |
"""
|
| 118 |
Memuat model hanya jika belum dimuat (lazy loading).
|
|
|
|
| 126 |
|
| 127 |
info = model_info[model_name]
|
| 128 |
try:
|
| 129 |
+
|
| 130 |
hf_model_path = info.get("hf_model_name", f"Lyon28/{model_name}")
|
| 131 |
|
|
|
|
| 132 |
models[model_name] = pipeline(
|
| 133 |
info["task"],
|
| 134 |
model=hf_model_path,
|
| 135 |
+
device="cpu",
|
| 136 |
+
torch_dtype=torch.float32
|
| 137 |
)
|
| 138 |
logger.info(f"✅ Model '{model_name}' (Path: {hf_model_path}) berhasil dimuat.")
|
| 139 |
except Exception as e:
|
|
|
|
| 271 |
# Untuk Hugging Face Spaces, port biasanya 7860
|
| 272 |
# Menggunakan HOST dari environment variable jika tersedia, default ke 0.0.0.0
|
| 273 |
# Debug=False untuk produksi
|
| 274 |
+
app.run(host=os.getenv('HOST', '0.0.0.0'), port=int(os.getenv('PORT', 7860)), debug=False)
|