teachyourselfcoding commited on
Commit
bc35043
1 Parent(s): 14aec93

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
3
+ import gradio as gr
4
+ import warnings
5
+ import os
6
+
7
+ # Remove command-line arguments parsing and use hardcoded defaults for simplicity in Spaces
8
+ MODEL_PATH = "/model/13B_hf"
9
+ LORA_PATH = "checkpoint-3000"
10
+ USE_TYPEWRITER = 1
11
+ USE_LOCAL = 1
12
+
13
+ tokenizer = LlamaTokenizer.from_pretrained(MODEL_PATH)
14
+
15
+ LOAD_8BIT = True
16
+ BASE_MODEL = MODEL_PATH
17
+ LORA_WEIGHTS = LORA_PATH
18
+
19
+ lora_bin_path = os.path.join(LORA_PATH, "adapter_model.bin")
20
+ if not os.path.exists(lora_bin_path) and USE_LOCAL:
21
+ # ... [rest of the path fixing logic]
22
+
23
+ # ... [rest of the device and model loading logic]
24
+
25
+ def generate_prompt(instruction, input=None):
26
+ # ... [rest of the generate_prompt function]
27
+
28
+ def evaluate(
29
+ input,
30
+ temperature=0.1,
31
+ top_p=0.75,
32
+ top_k=40,
33
+ num_beams=4,
34
+ max_new_tokens=128,
35
+ min_new_tokens=1,
36
+ repetition_penalty=2.0,
37
+ **kwargs,
38
+ ):
39
+ # ... [rest of the evaluate function]
40
+
41
+ gr.Interface(
42
+ fn=evaluate,
43
+ inputs=[
44
+ gr.components.Textbox(lines=2, label="Input", placeholder="Tell me about alpacas."),
45
+ # ... [rest of the inputs]
46
+ ],
47
+ outputs=[
48
+ gr.inputs.Textbox(lines=25, label="Output"),
49
+ ],
50
+ title="Chinese-Vicuna 中文小羊驼",
51
+ description="Chatlaw app trained on HK law data",
52
+ ).launch()