Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ctransformers import AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
greety = """
|
5 |
+
As a derivate work of [Linkedin Automation System](https://medium.com/@gathnex) by Gathnex,
|
6 |
+
Follow us on [linkedin](https://www.linkedin.com/company/gathnex/) and [Github](https://github.com/gathnexadmin). A special thanks to the Gathnex team members who made a significant contribution to this project.
|
7 |
+
"""
|
8 |
+
|
9 |
+
llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
|
10 |
+
model_type='mistral',
|
11 |
+
max_new_tokens = 1096,
|
12 |
+
threads = 3,
|
13 |
+
)
|
14 |
+
|
15 |
+
def stream(user_prompt):
|
16 |
+
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
|
17 |
+
E_INST = "</s>"
|
18 |
+
user, assistant = "<|user|>", "<|assistant|>"
|
19 |
+
prompt = f"{system_prompt}{E_INST}\n{user}\n{user_prompt.strip()}{E_INST}\n{assistant}\n"
|
20 |
+
for text in llm(prompt, stream=True, threads=3):
|
21 |
+
print(text, end="", flush=True)
|
22 |
+
|
23 |
+
css = """
|
24 |
+
h1 {
|
25 |
+
text-align: center;
|
26 |
+
}
|
27 |
+
#duplicate-button {
|
28 |
+
margin: auto;
|
29 |
+
color: white;
|
30 |
+
background: #1565c0;
|
31 |
+
border-radius: 100vh;
|
32 |
+
}
|
33 |
+
.contain {
|
34 |
+
max-width: 900px;
|
35 |
+
margin: auto;
|
36 |
+
padding-top: 1.5rem;
|
37 |
+
}
|
38 |
+
"""
|
39 |
+
|
40 |
+
chat_interface = gr.ChatInterface(
|
41 |
+
fn=stream,
|
42 |
+
additional_inputs_accordion_name = "Credentials",
|
43 |
+
#additional_inputs=[
|
44 |
+
# gr.Textbox(label="OpenAI Key", lines=1),
|
45 |
+
# gr.Textbox(label="Linkedin Access Token", lines=1),
|
46 |
+
],
|
47 |
+
stop_btn=None,
|
48 |
+
examples=[
|
49 |
+
["explain Large language model"],
|
50 |
+
["what is quantum computing"]
|
51 |
+
],
|
52 |
+
)
|
53 |
+
|
54 |
+
with gr.Blocks(css=css) as demo:
|
55 |
+
gr.HTML("<h1><center>Gathnex Linkedin Automation using Generative AI<h1><center>")
|
56 |
+
gr.HTML("<h3><center><a href='https://medium.com/@gathnex'>Gathnex AI</a>💬<h3><center>")
|
57 |
+
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
58 |
+
chat_interface.render()
|
59 |
+
gr.Markdown(greety)
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
demo.queue(max_size=10).launch()
|