Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,11 +11,15 @@ from safetensors.torch import load_file
|
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
from diffusers import FluxPipeline
|
| 13 |
|
| 14 |
-
# S3 Configuration
|
| 15 |
-
S3_BUCKET = "
|
| 16 |
-
S3_REGION = "
|
| 17 |
-
S3_ACCESS_KEY_ID = "
|
| 18 |
-
S3_SECRET_ACCESS_KEY = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Set up S3 client
|
| 21 |
s3_client = boto3.client('s3',
|
|
@@ -28,7 +32,6 @@ cache_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models")
|
|
| 28 |
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
| 29 |
os.environ["HF_HUB_CACHE"] = cache_path
|
| 30 |
os.environ["HF_HOME"] = cache_path
|
| 31 |
-
|
| 32 |
if not os.path.exists(cache_path):
|
| 33 |
os.makedirs(cache_path, exist_ok=True)
|
| 34 |
|
|
@@ -59,11 +62,11 @@ class InferenceRequest(BaseModel):
|
|
| 59 |
class Timer:
|
| 60 |
def __init__(self, method_name="timed process"):
|
| 61 |
self.method = method_name
|
| 62 |
-
|
| 63 |
def __enter__(self):
|
| 64 |
self.start = time.time()
|
| 65 |
print(f"{self.method} starts")
|
| 66 |
-
|
| 67 |
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 68 |
end = time.time()
|
| 69 |
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|
|
|
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
from diffusers import FluxPipeline
|
| 13 |
|
| 14 |
+
# S3 Configuration from environment variables
|
| 15 |
+
S3_BUCKET = os.getenv("S3_BUCKET")
|
| 16 |
+
S3_REGION = os.getenv("S3_REGION")
|
| 17 |
+
S3_ACCESS_KEY_ID = os.getenv("S3_ACCESS_KEY_ID")
|
| 18 |
+
S3_SECRET_ACCESS_KEY = os.getenv("S3_SECRET_ACCESS_KEY")
|
| 19 |
+
|
| 20 |
+
# Validate S3 environment variables
|
| 21 |
+
if not all([S3_BUCKET, S3_REGION, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY]):
|
| 22 |
+
raise ValueError("Missing required S3 environment variables")
|
| 23 |
|
| 24 |
# Set up S3 client
|
| 25 |
s3_client = boto3.client('s3',
|
|
|
|
| 32 |
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
| 33 |
os.environ["HF_HUB_CACHE"] = cache_path
|
| 34 |
os.environ["HF_HOME"] = cache_path
|
|
|
|
| 35 |
if not os.path.exists(cache_path):
|
| 36 |
os.makedirs(cache_path, exist_ok=True)
|
| 37 |
|
|
|
|
| 62 |
class Timer:
|
| 63 |
def __init__(self, method_name="timed process"):
|
| 64 |
self.method = method_name
|
| 65 |
+
|
| 66 |
def __enter__(self):
|
| 67 |
self.start = time.time()
|
| 68 |
print(f"{self.method} starts")
|
| 69 |
+
|
| 70 |
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 71 |
end = time.time()
|
| 72 |
print(f"{self.method} took {str(round(end - self.start, 2))}s")
|