Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import torch
|
|
5 |
|
6 |
# Device configuration (prioritize GPU if available)
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
-
model.to(device) # Move model to the selected device
|
9 |
|
10 |
# Load models and tokenizer efficiently
|
11 |
peft_model_id = "phearion/bigbrain-v0.0.1"
|
@@ -18,7 +17,8 @@ def greet(text):
|
|
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=
|
|
|
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
|
|
|
5 |
|
6 |
# Device configuration (prioritize GPU if available)
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
8 |
|
9 |
# Load models and tokenizer efficiently
|
10 |
peft_model_id = "phearion/bigbrain-v0.0.1"
|
|
|
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
|