Commit
·
050441a
1
Parent(s):
84b81f1
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,29 @@
|
|
| 1 |
from ctransformers import AutoModelForCausalLM
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
greety = """
|
| 5 |
-
Follow us [Gathnex](https://medium.com/@gathnex), [linkedin](https://www.linkedin.com/company/gathnex/) and [Github](https://github.com/gathnexadmin) for more update on Genrative AI, LLM,etc. A special thanks to the Gathnex team members who made a significant contribution to this project.
|
| 6 |
-
"""
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
def stream(prompt, UL):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return llm(prompt)
|
| 20 |
|
| 21 |
css = """
|
|
@@ -35,13 +43,11 @@ css = """
|
|
| 35 |
}
|
| 36 |
"""
|
| 37 |
|
|
|
|
|
|
|
| 38 |
chat_interface = gr.ChatInterface(
|
| 39 |
fn=stream,
|
| 40 |
-
|
| 41 |
-
#additional_inputs=[
|
| 42 |
-
# gr.Textbox(label="OpenAI Key", lines=1),
|
| 43 |
-
# gr.Textbox(label="Linkedin Access Token", lines=1),
|
| 44 |
-
#],
|
| 45 |
stop_btn=None,
|
| 46 |
examples=[
|
| 47 |
["explain Large language model"],
|
|
|
|
| 1 |
from ctransformers import AutoModelForCausalLM
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
llms = {
|
| 6 |
+
"tinnyllama":{"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 |
+
"llama2":{"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 |
+
def stream(prompt, llm_name, UL):
|
| 18 |
+
|
| 19 |
+
prefix=llms[llm_name]['prefix']
|
| 20 |
+
suffix=llms[llm_name]['suffix']
|
| 21 |
+
user="""
|
| 22 |
+
{prompt}"""
|
| 23 |
+
|
| 24 |
+
llm = AutoModelForCausalLM.from_pretrained(llms[llm_name]['name'], model_file=llms[llm_name]['file'])
|
| 25 |
+
|
| 26 |
+
prompt = f"{prefix}{user.replace('{prompt}', item.prompt)}{suffix}"
|
| 27 |
return llm(prompt)
|
| 28 |
|
| 29 |
css = """
|
|
|
|
| 43 |
}
|
| 44 |
"""
|
| 45 |
|
| 46 |
+
select_llm = gradio.Dropdown(choices=llms.keys(), value=llms.keys()[0], 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"],
|