Spaces:
Sleeping
Sleeping
Hjgugugjhuhjggg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import logging
|
3 |
import threading
|
4 |
import boto3
|
5 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig, StoppingCriteriaList
|
6 |
from fastapi import FastAPI, HTTPException, Request
|
7 |
from pydantic import BaseModel, field_validator
|
8 |
from huggingface_hub import hf_hub_download
|
@@ -77,7 +77,7 @@ class S3ModelLoader:
|
|
77 |
def download_model_from_huggingface(self, model_name):
|
78 |
try:
|
79 |
logging.info(f"Downloading model {model_name} from Hugging Face...")
|
80 |
-
model_dir = hf_hub_download(model_name, token=HUGGINGFACE_HUB_TOKEN)
|
81 |
model_files = os.listdir(model_dir)
|
82 |
for model_file in model_files:
|
83 |
s3_path = f"lilmeaty_garca/{model_name}/{model_file}"
|
@@ -200,14 +200,3 @@ def download_model_from_s3_or_hf(model_name):
|
|
200 |
except Exception:
|
201 |
model_loader.download_model_from_huggingface(model_name)
|
202 |
return model_loader._download_from_s3(model_name)
|
203 |
-
|
204 |
-
def ensure_s3_directories(model_name):
|
205 |
-
try:
|
206 |
-
s3_path = f"lilmeaty_garca/{model_name}"
|
207 |
-
s3_client.put_object(Bucket=S3_BUCKET_NAME, Key=s3_path)
|
208 |
-
except Exception as e:
|
209 |
-
logging.error(f"Error ensuring S3 directories exist for model {model_name}: {e}")
|
210 |
-
|
211 |
-
if __name__ == "__main__":
|
212 |
-
import uvicorn
|
213 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
2 |
import logging
|
3 |
import threading
|
4 |
import boto3
|
5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig, StoppingCriteriaList
|
6 |
from fastapi import FastAPI, HTTPException, Request
|
7 |
from pydantic import BaseModel, field_validator
|
8 |
from huggingface_hub import hf_hub_download
|
|
|
77 |
def download_model_from_huggingface(self, model_name):
|
78 |
try:
|
79 |
logging.info(f"Downloading model {model_name} from Hugging Face...")
|
80 |
+
model_dir = hf_hub_download(model_name, token=HUGGINGFACE_HUB_TOKEN, filename=None)
|
81 |
model_files = os.listdir(model_dir)
|
82 |
for model_file in model_files:
|
83 |
s3_path = f"lilmeaty_garca/{model_name}/{model_file}"
|
|
|
200 |
except Exception:
|
201 |
model_loader.download_model_from_huggingface(model_name)
|
202 |
return model_loader._download_from_s3(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|