Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException
|
|
2 |
from pydantic import BaseModel
|
3 |
from transformers import pipeline
|
4 |
import logging
|
|
|
5 |
|
6 |
# Configure logging
|
7 |
logging.basicConfig(level=logging.INFO)
|
@@ -9,12 +10,17 @@ logger = logging.getLogger(__name__)
|
|
9 |
|
10 |
app = FastAPI(title="SQL Coder API")
|
11 |
|
|
|
|
|
|
|
|
|
12 |
# Initialize pipeline
|
13 |
try:
|
14 |
pipe = pipeline("text-generation",
|
15 |
model="defog/llama-3-sqlcoder-8b",
|
16 |
device_map="auto",
|
17 |
-
torch_dtype="auto"
|
|
|
18 |
logger.info("Pipeline initialized successfully")
|
19 |
except Exception as e:
|
20 |
logger.error(f"Error initializing pipeline: {str(e)}")
|
|
|
2 |
from pydantic import BaseModel
|
3 |
from transformers import pipeline
|
4 |
import logging
|
5 |
+
import os
|
6 |
|
7 |
# Configure logging
|
8 |
logging.basicConfig(level=logging.INFO)
|
|
|
10 |
|
11 |
app = FastAPI(title="SQL Coder API")
|
12 |
|
13 |
+
# Ensure cache directory exists
|
14 |
+
cache_dir = os.getenv('TRANSFORMERS_CACHE', '/home/user/.cache/huggingface')
|
15 |
+
os.makedirs(cache_dir, exist_ok=True)
|
16 |
+
|
17 |
# Initialize pipeline
|
18 |
try:
|
19 |
pipe = pipeline("text-generation",
|
20 |
model="defog/llama-3-sqlcoder-8b",
|
21 |
device_map="auto",
|
22 |
+
torch_dtype="auto",
|
23 |
+
cache_dir=cache_dir)
|
24 |
logger.info("Pipeline initialized successfully")
|
25 |
except Exception as e:
|
26 |
logger.error(f"Error initializing pipeline: {str(e)}")
|