Spaces:
Running
Running
optimized funcion for cpu usages
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ app = FastAPI()
|
|
9 |
# Load the DeepSeek model and tokenizer
|
10 |
MODEL_NAME = "deepseek-ai/deepseek-coder-1.3b-instruct"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.
|
13 |
|
14 |
|
15 |
class ChatRequest(BaseModel):
|
@@ -19,9 +19,10 @@ def generate_sql_query(user_input: str) -> str:
|
|
19 |
"""
|
20 |
Generate an SQL query from a natural language query using the DeepSeek model.
|
21 |
"""
|
22 |
-
inputs = tokenizer(user_input, return_tensors="pt")
|
23 |
-
outputs = model.generate(**inputs, max_length=400)
|
24 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
25 |
return sql_query
|
26 |
|
27 |
|
|
|
9 |
# Load the DeepSeek model and tokenizer
|
10 |
MODEL_NAME = "deepseek-ai/deepseek-coder-1.3b-instruct"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float32).to("cpu")
|
13 |
|
14 |
|
15 |
class ChatRequest(BaseModel):
|
|
|
19 |
"""
|
20 |
Generate an SQL query from a natural language query using the DeepSeek model.
|
21 |
"""
|
22 |
+
inputs = tokenizer(user_input, return_tensors="pt", padding="longest", truncation=True)
|
23 |
+
outputs = model.generate(**inputs, max_length=400, do_sample=False, num_beams=1)
|
24 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
25 |
+
|
26 |
return sql_query
|
27 |
|
28 |
|