Spaces:
Runtime error
Runtime error
Commit
·
c349adc
1
Parent(s):
2846ff5
changed to CPU 2
Browse files
app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
from model import load_model, answer
|
2 |
from components import create_app_layout
|
3 |
import torch
|
|
|
|
|
|
|
4 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
|
6 |
# Load the model and tokenizer
|
|
|
1 |
from model import load_model, answer
|
2 |
from components import create_app_layout
|
3 |
import torch
|
4 |
+
|
5 |
+
|
6 |
+
# Check if a GPU is available; otherwise, use the CPU
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
9 |
# Load the model and tokenizer
|
model.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
from unsloth import FastLanguageModel
|
2 |
-
import torch
|
3 |
from prompts import metallurgy_prompt
|
|
|
|
|
4 |
|
5 |
-
# Check if a GPU is available; otherwise, use the CPU
|
6 |
|
7 |
def load_model():
|
8 |
max_seq_length = 2048
|
@@ -22,7 +22,7 @@ def answer(model, tokenizer, query: str) -> str:
|
|
22 |
inputs = tokenizer(
|
23 |
[metallurgy_prompt.format(query, "", "")],
|
24 |
return_tensors="pt"
|
25 |
-
).to(
|
26 |
|
27 |
outputs = model.generate(**inputs, use_cache=True)
|
28 |
result = tokenizer.batch_decode(outputs)
|
|
|
1 |
from unsloth import FastLanguageModel
|
|
|
2 |
from prompts import metallurgy_prompt
|
3 |
+
import torch
|
4 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
|
|
|
6 |
|
7 |
def load_model():
|
8 |
max_seq_length = 2048
|
|
|
22 |
inputs = tokenizer(
|
23 |
[metallurgy_prompt.format(query, "", "")],
|
24 |
return_tensors="pt"
|
25 |
+
).to(device)
|
26 |
|
27 |
outputs = model.generate(**inputs, use_cache=True)
|
28 |
result = tokenizer.batch_decode(outputs)
|