Update app.py
Browse files
app.py
CHANGED
@@ -10,15 +10,15 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
10 |
peft_model_id = "phearion/bigbrain-v0.0.1"
|
11 |
config = PeftConfig.from_pretrained(peft_model_id)
|
12 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
13 |
-
model = PeftModel.from_pretrained(peft_model_id)
|
|
|
14 |
|
15 |
def greet(text):
|
16 |
with torch.no_grad(): # Disable gradient calculation for inference
|
17 |
batch = tokenizer(text, return_tensors='pt').to(device) # Move tensors to device
|
18 |
with torch.cuda.amp.autocast(): # Enable mixed-precision if available
|
19 |
output_tokens = model.generate(**batch, max_new_tokens=15)
|
20 |
-
return tokenizer.decode(output_tokens[0], skip_special_tokens=
|
21 |
-
True)
|
22 |
|
23 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="PEFT Model for Big Brain", live=True)
|
24 |
iface.launch(share=True) # Share directly to Gradio Space
|
|
|
10 |
peft_model_id = "phearion/bigbrain-v0.0.1"
|
11 |
config = PeftConfig.from_pretrained(peft_model_id)
|
12 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
13 |
+
model = PeftModel.from_pretrained(peft_model_id)
|
14 |
+
model.to(device)
|
15 |
|
16 |
def greet(text):
|
17 |
with torch.no_grad(): # Disable gradient calculation for inference
|
18 |
batch = tokenizer(text, return_tensors='pt').to(device) # Move tensors to device
|
19 |
with torch.cuda.amp.autocast(): # Enable mixed-precision if available
|
20 |
output_tokens = model.generate(**batch, max_new_tokens=15)
|
21 |
+
return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
|
|
22 |
|
23 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="PEFT Model for Big Brain", live=True)
|
24 |
iface.launch(share=True) # Share directly to Gradio Space
|