Yehor commited on
Commit
b166270
·
verified ·
1 Parent(s): b9aeee8

Create app.py

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