Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,51 +1,60 @@
|
|
| 1 |
from ctransformers import AutoModelForCausalLM
|
| 2 |
-
from gradio import Chatbot, Interface
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
system_prompt = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
| 16 |
E_INST = "</s>"
|
| 17 |
user, assistant = "<|user|>", "<|assistant|>"
|
| 18 |
-
prompt = f"{system_prompt}{E_INST}\n"
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
gr.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
state = gr.State([])
|
| 45 |
-
|
| 46 |
-
msg.submit(respond, [msg, state], [chatbot, state])
|
| 47 |
-
clear.click(lambda: ([], []), None, [chatbot, state])
|
| 48 |
-
|
| 49 |
-
# Launch Gradio app
|
| 50 |
if __name__ == "__main__":
|
| 51 |
-
demo.
|
|
|
|
| 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 |
+
llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
|
| 9 |
+
model_type='mistral',
|
| 10 |
+
max_new_tokens = 1096,
|
| 11 |
+
threads = 3,
|
| 12 |
)
|
| 13 |
|
| 14 |
+
def stream(prompt, UL):
|
| 15 |
+
system_prompt = 'You are a helpful AI assistant'
|
|
|
|
| 16 |
E_INST = "</s>"
|
| 17 |
user, assistant = "<|user|>", "<|assistant|>"
|
| 18 |
+
prompt = f"{system_prompt}{E_INST}\n{user}\n{prompt.strip()}{E_INST}\n{assistant}\n"
|
| 19 |
+
return llm(prompt)
|
| 20 |
+
|
| 21 |
+
css = """
|
| 22 |
+
h1 {
|
| 23 |
+
text-align: center;
|
| 24 |
+
}
|
| 25 |
+
#duplicate-button {
|
| 26 |
+
margin: auto;
|
| 27 |
+
color: white;
|
| 28 |
+
background: #1565c0;
|
| 29 |
+
border-radius: 100vh;
|
| 30 |
+
}
|
| 31 |
+
.contain {
|
| 32 |
+
max-width: 900px;
|
| 33 |
+
margin: auto;
|
| 34 |
+
padding-top: 1.5rem;
|
| 35 |
+
}
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
chat_interface = gr.ChatInterface(
|
| 39 |
+
fn=stream,
|
| 40 |
+
#additional_inputs_accordion_name = "Credentials",
|
| 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"],
|
| 48 |
+
["what is quantum computing"]
|
| 49 |
+
],
|
| 50 |
)
|
| 51 |
|
| 52 |
+
with gr.Blocks(css=css) as demo:
|
| 53 |
+
gr.HTML("<h1><center>Gathnex Free LLM Deployment Space<h1><center>")
|
| 54 |
+
gr.HTML("<h3><center><a href='https://medium.com/@gathnex'>Gathnex AI</a>💬<h3><center>")
|
| 55 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
| 56 |
+
chat_interface.render()
|
| 57 |
+
gr.Markdown(greety)
|
| 58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
demo.queue(max_size=10).launch()
|