Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
Estella Explainer — Hugging Face Space
|
| 3 |
A math reading coach for grades 3–8.
|
| 4 |
"""
|
| 5 |
|
|
@@ -53,21 +53,22 @@ print(f"Loading base model: {BASE_MODEL_ID}")
|
|
| 53 |
|
| 54 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
BASE_MODEL_ID,
|
| 56 |
-
|
| 57 |
low_cpu_mem_usage=True,
|
| 58 |
**HUB_ARGS,
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
print(f"Loading Estella adapter: {ADAPTER_ID}")
|
| 64 |
|
| 65 |
model = PeftModel.from_pretrained(
|
| 66 |
base_model,
|
| 67 |
ADAPTER_ID,
|
|
|
|
| 68 |
**HUB_ARGS,
|
| 69 |
)
|
| 70 |
|
|
|
|
|
|
|
| 71 |
model = model.to("cuda")
|
| 72 |
model.eval()
|
| 73 |
|
|
@@ -136,13 +137,11 @@ def ask_estella(message: str, history: list) -> str:
|
|
| 136 |
|
| 137 |
generated_tokens = outputs[0][input_length:]
|
| 138 |
|
| 139 |
-
|
| 140 |
generated_tokens,
|
| 141 |
skip_special_tokens=True,
|
| 142 |
).strip()
|
| 143 |
|
| 144 |
-
return hint
|
| 145 |
-
|
| 146 |
|
| 147 |
demo = gr.ChatInterface(
|
| 148 |
fn=ask_estella,
|
|
|
|
| 1 |
"""
|
| 2 |
+
Estella Explainer — Hugging Face ZeroGPU Space
|
| 3 |
A math reading coach for grades 3–8.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 53 |
|
| 54 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
BASE_MODEL_ID,
|
| 56 |
+
dtype=torch.float16,
|
| 57 |
low_cpu_mem_usage=True,
|
| 58 |
**HUB_ARGS,
|
| 59 |
)
|
| 60 |
|
| 61 |
+
print(f"Loading adapter on CPU: {ADAPTER_ID}")
|
|
|
|
|
|
|
| 62 |
|
| 63 |
model = PeftModel.from_pretrained(
|
| 64 |
base_model,
|
| 65 |
ADAPTER_ID,
|
| 66 |
+
torch_device="cpu",
|
| 67 |
**HUB_ARGS,
|
| 68 |
)
|
| 69 |
|
| 70 |
+
print("Moving combined model to CUDA.")
|
| 71 |
+
|
| 72 |
model = model.to("cuda")
|
| 73 |
model.eval()
|
| 74 |
|
|
|
|
| 137 |
|
| 138 |
generated_tokens = outputs[0][input_length:]
|
| 139 |
|
| 140 |
+
return tokenizer.decode(
|
| 141 |
generated_tokens,
|
| 142 |
skip_special_tokens=True,
|
| 143 |
).strip()
|
| 144 |
|
|
|
|
|
|
|
| 145 |
|
| 146 |
demo = gr.ChatInterface(
|
| 147 |
fn=ask_estella,
|