SrejonAhamed commited on
Commit
de3fa38
1 Parent(s): 352ad9c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()