Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
# Load tokenizer and model
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("TuringsSolutions/Gemma2LegalEdition", trust_remote_code=True)
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("TuringsSolutions/Gemma2LegalEdition", trust_remote_code=True)
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def predict(prompt, temperature, max_tokens):
|
| 9 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
| 10 |
outputs = model.generate(
|
| 11 |
**inputs,
|
| 12 |
max_new_tokens=max_tokens,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
|
| 5 |
# Load tokenizer and model
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("TuringsSolutions/Gemma2LegalEdition", trust_remote_code=True)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained("TuringsSolutions/Gemma2LegalEdition", trust_remote_code=True)
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
model.to(device)
|
| 10 |
|
| 11 |
def predict(prompt, temperature, max_tokens):
|
| 12 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 13 |
outputs = model.generate(
|
| 14 |
**inputs,
|
| 15 |
max_new_tokens=max_tokens,
|