Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,37 +9,15 @@ print(zero.device) # <-- 'cpu' 🤔
|
|
9 |
@spaces.GPU
|
10 |
def greet(n):
|
11 |
print(zero.device) # <-- 'cuda:0' 🤗
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
print(f'status: {m}')
|
22 |
-
return m
|
23 |
-
|
24 |
-
def load_model(fp):
|
25 |
-
from llama_cpp import Llama, LlamaGrammar
|
26 |
-
|
27 |
-
print(f'Loading model: {fp}')
|
28 |
-
model_file=fp
|
29 |
-
llm = Llama(
|
30 |
-
model_path=model_file,
|
31 |
-
n_gpu_layers=-1, verbose=True
|
32 |
-
)
|
33 |
-
|
34 |
-
grammar = LlamaGrammar.from_string('''
|
35 |
-
root ::= sentence
|
36 |
-
answer ::= (weather | complaint | yesno | gen)
|
37 |
-
weather ::= ("Sunny." | "Cloudy." | "Rainy.")
|
38 |
-
complaint ::= "I don't like talking about the weather."
|
39 |
-
yesno ::= ("Yes." | "No.")
|
40 |
-
gen ::= "1. " [A-Z] [a-z] [a-z]*
|
41 |
-
sentence ::= [A-Z] [A-Za-z0-9 ,-]* ("." | "!" | "?")
|
42 |
-
''')
|
43 |
|
44 |
prompts = [
|
45 |
"How's the weather in London?",
|
@@ -63,6 +41,27 @@ def load_model(fp):
|
|
63 |
print(output['choices'][0]['text'])
|
64 |
print()
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
load_model(download_model())
|
68 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
|
|
9 |
@spaces.GPU
|
10 |
def greet(n):
|
11 |
print(zero.device) # <-- 'cuda:0' 🤗
|
12 |
+
grammar = LlamaGrammar.from_string('''
|
13 |
+
root ::= sentence
|
14 |
+
answer ::= (weather | complaint | yesno | gen)
|
15 |
+
weather ::= ("Sunny." | "Cloudy." | "Rainy.")
|
16 |
+
complaint ::= "I don't like talking about the weather."
|
17 |
+
yesno ::= ("Yes." | "No.")
|
18 |
+
gen ::= "1. " [A-Z] [a-z] [a-z]*
|
19 |
+
sentence ::= [A-Z] [A-Za-z0-9 ,-]* ("." | "!" | "?")
|
20 |
+
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
prompts = [
|
23 |
"How's the weather in London?",
|
|
|
41 |
print(output['choices'][0]['text'])
|
42 |
print()
|
43 |
|
44 |
+
return f"Hello {zero + n} Tensor"
|
45 |
+
|
46 |
+
def download_model():
|
47 |
+
|
48 |
+
REPO_ID = "TheBloke/Llama-2-7B-GGUF"
|
49 |
+
FILENAME = "llama-2-7b.Q5_K_S.gguf"
|
50 |
+
|
51 |
+
print(f'Downloading model {REPO_ID}/{FILENAME}')
|
52 |
+
m = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
53 |
+
print(f'status: {m}')
|
54 |
+
return m
|
55 |
+
|
56 |
+
def load_model(fp):
|
57 |
+
from llama_cpp import Llama, LlamaGrammar
|
58 |
+
|
59 |
+
print(f'Loading model: {fp}')
|
60 |
+
model_file=fp
|
61 |
+
llm = Llama(
|
62 |
+
model_path=model_file,
|
63 |
+
n_gpu_layers=-1, verbose=True
|
64 |
+
)
|
65 |
|
66 |
load_model(download_model())
|
67 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|