ML610 commited on
Commit
ff11a2a
·
1 Parent(s): 9c310c3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import ctransformers
3
+
4
+ configObj = ctransformers.Config(stop=["\n", 'User'])
5
+ config = ctransformers.AutoConfig(config=configObj, model_type='llama')
6
+ config.config.stop = ["\n"]
7
+
8
+ llm = ctransformers.AutoModelForCausalLM.from_pretrained('./llama-2-7b.ggmlv3.q4_K_S.bin', config=config)
9
+
10
+ def complete(prompt, stop=["User", "Assistant"]):
11
+ tokens = llm.tokenize(prompt)
12
+ output = ''
13
+ for token in llm.generate(tokens):
14
+ result = llm.detokenize(token)
15
+ output += result
16
+ for word in stop:
17
+ if word in output:
18
+ print('\n')
19
+ return output
20
+ print(result, end='',flush=True)
21
+
22
+ print('\n')
23
+ return output
24
+
25
+ title = "llama2-7b-chat-ggml"
26
+ description = "This space is an attempt to run the GGML 4 bit quantized version of 'llama2-7b-chat' on a CPU"
27
+
28
+ example_1 = "Write a 7 line poem on AI"
29
+ example_2 = "Tell me a joke"
30
+
31
+ examples = [example_1, example_2]
32
+
33
+
34
+ UI = gr.Interface(
35
+ fn=generate_code,
36
+ inputs=gr.Textbox(label="user_prompt", placeholder="Ask your queries here...."),
37
+ outputs=gr.Textbox(label="Assistant"),
38
+ title=title,
39
+ description=description,
40
+ examples=examples
41
+ )
42
+
43
+ UI.launch()