Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
|
3 |
+
import torch
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
8 |
+
|
9 |
+
max_seq_length = 2048
|
10 |
+
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("ua-l/gemma-2-9b-legal-steps200-merged-16bit-uk")
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
13 |
+
"ua-l/gemma-2-9b-legal-steps200-merged-16bit-uk",
|
14 |
+
quantization_config=quantization_config,
|
15 |
+
device_map='auto'
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
@spaces.GPU
|
20 |
+
def predict(question):
|
21 |
+
inputs = tokenizer(
|
22 |
+
[f'''### Question:
|
23 |
+
{question}
|
24 |
+
|
25 |
+
### Answer:
|
26 |
+
'''], return_tensors = "pt").to("cuda")
|
27 |
+
|
28 |
+
outputs = model.generate(**inputs, max_new_tokens = 128)
|
29 |
+
|
30 |
+
results = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
31 |
+
|
32 |
+
return results[0]
|
33 |
+
|
34 |
+
inputs = gr.Textbox(lines=2, label="Enter a question", value="Як отримати виплати ВПО?")
|
35 |
+
|
36 |
+
outputs = gr.Textbox(label="Answer")
|
37 |
+
|
38 |
+
demo = gr.Interface(fn=predict, inputs=inputs, outputs=outputs)
|
39 |
+
demo.launch()
|
40 |
+
|