Spaces:
No application file
No application file
File size: 1,190 Bytes
b166270 aa8cda8 53fc999 aa8cda8 b166270 b7cbc3b 53fc999 b166270 aa8cda8 b166270 aa8cda8 53fc999 b7cbc3b 53fc999 b7cbc3b b166270 01c7904 b166270 b7cbc3b b166270 b7cbc3b b166270 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import spaces
import torch
import torch._dynamo
import gradio as gr
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer, BitsAndBytesConfig
torch._dynamo.config.suppress_errors = True
torch._dynamo.disable()
max_seq_length = 2048
dtype = (
None
)
load_in_4bit = True
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
# bnb_4bit_compute_dtype=torch.float16,
)
tokenizer = AutoTokenizer.from_pretrained("ua-l/gemma-2-9b-legal-uk")
model = AutoPeftModelForCausalLM.from_pretrained(
"ua-l/gemma-2-9b-legal-uk",
quantization_config=quantization_config,
device_map='auto'
)
@spaces.GPU
def predict(question):
inputs = tokenizer(
[f'''### Question:
{question}
### Answer:
'''], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 128)
results = tokenizer.batch_decode(outputs, skip_special_tokens=True)
return results[0]
inputs = gr.Textbox(lines=2, label="Enter a question", value="Як отримати виплати ВПО?")
outputs = gr.Textbox(label="Answer")
demo = gr.Interface(fn=predict, inputs=inputs, outputs=outputs)
demo.launch()
|