Yehor commited on
Commit
c241961
·
verified ·
1 Parent(s): 0a4eb65

Create app.py

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