Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ class ConflictDetectionRequest(BaseModel):
|
|
| 24 |
# -----------------------------
|
| 25 |
def build_prompt(req1, req2, prompt_type="zero-shot"):
|
| 26 |
if prompt_type == "zero-shot":
|
| 27 |
-
return f"Do the following sentences contradict each other,
|
| 28 |
elif prompt_type == "few-shot":
|
| 29 |
examples = (
|
| 30 |
"Example 1:\n"
|
|
@@ -38,20 +38,23 @@ def build_prompt(req1, req2, prompt_type="zero-shot"):
|
|
| 38 |
)
|
| 39 |
return examples + f"Now answer: Do the following sentences contradict each other? 1.{req1} 2.{req2}"
|
| 40 |
else:
|
| 41 |
-
return f"Do the following sentences contradict each other,
|
| 42 |
|
| 43 |
# -----------------------------
|
| 44 |
# Startup: load DeepSeek once
|
| 45 |
# -----------------------------
|
| 46 |
@app.on_event("startup")
|
| 47 |
def load_models():
|
| 48 |
-
print("Loading
|
| 49 |
-
|
| 50 |
-
app.state.deepseek_tokenizer = AutoTokenizer.from_pretrained(
|
| 51 |
app.state.deepseek_tokenizer.pad_token = app.state.deepseek_tokenizer.eos_token
|
|
|
|
| 52 |
app.state.deepseek_model = AutoModelForCausalLM.from_pretrained(
|
| 53 |
-
|
| 54 |
-
torch_dtype=
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
|
|
|
|
| 24 |
# -----------------------------
|
| 25 |
def build_prompt(req1, req2, prompt_type="zero-shot"):
|
| 26 |
if prompt_type == "zero-shot":
|
| 27 |
+
return f"Do the following sentences contradict each other, yes or no: 1.{req1} 2.{req2}"
|
| 28 |
elif prompt_type == "few-shot":
|
| 29 |
examples = (
|
| 30 |
"Example 1:\n"
|
|
|
|
| 38 |
)
|
| 39 |
return examples + f"Now answer: Do the following sentences contradict each other? 1.{req1} 2.{req2}"
|
| 40 |
else:
|
| 41 |
+
return f"Do the following sentences contradict each other, yes or no: 1.{req1} 2.{req2}"
|
| 42 |
|
| 43 |
# -----------------------------
|
| 44 |
# Startup: load DeepSeek once
|
| 45 |
# -----------------------------
|
| 46 |
@app.on_event("startup")
|
| 47 |
def load_models():
|
| 48 |
+
print("Loading DeepSeek model into memory...")
|
| 49 |
+
model_name = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
|
| 50 |
+
app.state.deepseek_tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 51 |
app.state.deepseek_tokenizer.pad_token = app.state.deepseek_tokenizer.eos_token
|
| 52 |
+
|
| 53 |
app.state.deepseek_model = AutoModelForCausalLM.from_pretrained(
|
| 54 |
+
model_name,
|
| 55 |
+
torch_dtype="auto",
|
| 56 |
+
device_map="auto",
|
| 57 |
+
offload_folder="offload" # folder to store offloaded weights
|
| 58 |
)
|
| 59 |
|
| 60 |
|