Spaces:
Runtime error
Runtime error
daniellefranca96
commited on
Commit
•
d9c9b95
1
Parent(s):
d6d765e
Update app.py
Browse files
app.py
CHANGED
@@ -3,19 +3,20 @@ import gradio as gr
|
|
3 |
|
4 |
|
5 |
llms = {
|
6 |
-
"
|
7 |
-
"orca2":{"name": "TheBloke/Orca-2-7B-GGUF", "file":"orca-2-7b.Q4_K_M.gguf", "suffix":"<|im_end|><|im_start|>assistant", "prefix":"<|im_start|>system You are a helpful assistant<|im_end|><|im_start|>user "},
|
8 |
-
"zephyr":{"name": "TheBloke/zephyr-7B-beta-GGUF", "file":"zephyr-7b-beta.Q4_K_M.gguf", "suffix":"</s><|assistant|>", "prefix":"<|system|>You are a helpful assistant</s><|user|> "},
|
9 |
-
"mixtral":{"name": "TheBloke/Mistral-7B-Instruct-v0.1-GGUF", "file":"mistral-7b-instruct-v0.1.Q4_K_M.gguf", "suffix":"[/INST]", "prefix":"<s>[INST] "},
|
10 |
-
"llama2":{"name": "TheBloke/Llama-2-7B-Chat-GGUF", "file":"llama-2-7b-chat.Q4_K_M.gguf", "suffix":"[/INST]", "prefix":"[INST] <<SYS>> You are a helpful assistant <</SYS>>"},
|
11 |
-
"
|
12 |
}
|
13 |
|
14 |
for k in llms.keys():
|
15 |
AutoModelForCausalLM.from_pretrained(llms[k]['name'], model_file=llms[k]['file'])
|
16 |
|
17 |
-
|
18 |
-
|
|
|
19 |
prefix=llms[llm_name]['prefix']
|
20 |
suffix=llms[llm_name]['suffix']
|
21 |
user="""
|
@@ -23,43 +24,16 @@ def stream(prompt, llm_name, UL):
|
|
23 |
|
24 |
llm = AutoModelForCausalLM.from_pretrained(llms[llm_name]['name'], model_file=llms[llm_name]['file'])
|
25 |
|
26 |
-
prompt = f"{prefix}{user.replace('{prompt}',
|
27 |
return llm(prompt)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
margin: auto;
|
35 |
-
color: white;
|
36 |
-
background: #1565c0;
|
37 |
-
border-radius: 100vh;
|
38 |
-
}
|
39 |
-
.contain {
|
40 |
-
max-width: 900px;
|
41 |
-
margin: auto;
|
42 |
-
padding-top: 1.5rem;
|
43 |
-
}
|
44 |
-
"""
|
45 |
-
|
46 |
-
select_llm = gr.Dropdown(choices=llms.keys(), value='tinnyllama', max_choices=1)
|
47 |
-
|
48 |
-
chat_interface = gr.ChatInterface(
|
49 |
-
fn=stream,
|
50 |
-
additional_inputs=[select_llm],
|
51 |
-
stop_btn=None,
|
52 |
-
examples=[
|
53 |
-
["explain Large language model"],
|
54 |
-
["what is quantum computing"]
|
55 |
-
],
|
56 |
)
|
57 |
|
58 |
-
with gr.Blocks(css=css) as demo:
|
59 |
-
gr.HTML("<h1><center>Gathnex Free LLM Deployment Space<h1><center>")
|
60 |
-
gr.HTML("<h3><center><a href='https://medium.com/@gathnex'>Gathnex AI</a>💬<h3><center>")
|
61 |
-
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
62 |
-
chat_interface.render()
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
-
|
|
|
3 |
|
4 |
|
5 |
llms = {
|
6 |
+
"tinyllama":{"name": "TheBloke/TinyLlama-1.1B-1T-OpenOrca-GGUF", "file":"tinyllama-1.1b-1t-openorca.Q4_K_M.gguf", "suffix":"<|im_end|><|im_start|>assistant", "prefix":"<|im_start|>system You are a helpful assistant <|im_end|><|im_start|>user"},
|
7 |
+
"orca2":{"name": "TheBloke/Orca-2-7B-GGUF", "file":"orca-2-7b.Q4_K_M.gguf", "suffix":"<|im_end|><|im_start|>assistant", "prefix":"<|im_start|>system You are a helpful assistant<|im_end|><|im_start|>user "},
|
8 |
+
"zephyr":{"name": "TheBloke/zephyr-7B-beta-GGUF", "file":"zephyr-7b-beta.Q4_K_M.gguf", "suffix":"</s><|assistant|>", "prefix":"<|system|>You are a helpful assistant</s><|user|> "},
|
9 |
+
"mixtral":{"name": "TheBloke/Mistral-7B-Instruct-v0.1-GGUF", "file":"mistral-7b-instruct-v0.1.Q4_K_M.gguf", "suffix":"[/INST]", "prefix":"<s>[INST] "},
|
10 |
+
"llama2":{"name": "TheBloke/Llama-2-7B-Chat-GGUF", "file":"llama-2-7b-chat.Q4_K_M.gguf", "suffix":"[/INST]", "prefix":"[INST] <<SYS>> You are a helpful assistant <</SYS>>"},
|
11 |
+
"solar":{"name": "TheBloke/SOLAR-10.7B-Instruct-v1.0-GGUF", "file":"solar-10.7b-instruct-v1.0.Q4_K_M.gguf", "suffix":"\n### Assistant:\n", "prefix":"### User:\n"}
|
12 |
}
|
13 |
|
14 |
for k in llms.keys():
|
15 |
AutoModelForCausalLM.from_pretrained(llms[k]['name'], model_file=llms[k]['file'])
|
16 |
|
17 |
+
import gradio as gr
|
18 |
+
|
19 |
+
def predict(prompt, llm_name):
|
20 |
prefix=llms[llm_name]['prefix']
|
21 |
suffix=llms[llm_name]['suffix']
|
22 |
user="""
|
|
|
24 |
|
25 |
llm = AutoModelForCausalLM.from_pretrained(llms[llm_name]['name'], model_file=llms[llm_name]['file'])
|
26 |
|
27 |
+
prompt = f"{prefix}{user.replace('{prompt}', prompt)}{suffix}"
|
28 |
return llm(prompt)
|
29 |
|
30 |
+
# Create the Gradio interface
|
31 |
+
interface = gr.Interface(
|
32 |
+
fn=predict,
|
33 |
+
inputs=[gr.Textbox(label="Prompt", lines=20), gr.Dropdown(choices=list(llms), label="Select an LLM", value="tinyllama")],
|
34 |
+
outputs="text"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
)
|
36 |
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
if __name__ == "__main__":
|
39 |
+
interface.launch()
|