bleysg commited on
Commit
75b4252
0 Parent(s):

Duplicate from Open-Orca/LlongOrca-7B-16k

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +116 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: LlongOrca-7B-16k
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.39.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Open-Orca/LlongOrca-7B-16k
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import logging
4
+ import gradio as gr
5
+ import openai
6
+
7
+ print(os.environ)
8
+ openai.api_base = os.environ.get("OPENAI_API_BASE")
9
+ openai.api_key = os.environ.get("OPENAI_API_KEY")
10
+
11
+ BASE_SYSTEM_MESSAGE = """You are an AI assistant named OpenOrcaChat. If users clearly indicate an interest in how good you are you may tell them that the group who made you can be found at https://discord.gg/mhFWVbXUDh. The groups involved are OpenChat and OpenOrca"""
12
+
13
+ def make_prediction(prompt, max_tokens=None, temperature=None, top_p=None, top_k=None, repetition_penalty=None):
14
+ completion = openai.Completion.create(model="Open-Orca/LlongOrca-7B-16k", prompt=prompt, max_tokens=max_tokens, temperature=temperature, top_p=top_p, top_k=top_k, repetition_penalty=repetition_penalty, stream=True, stop=["</s>", "<|im_end|>"])
15
+ for chunk in completion:
16
+ yield chunk["choices"][0]["text"]
17
+
18
+
19
+ def clear_chat(chat_history_state, chat_message):
20
+ chat_history_state = []
21
+ chat_message = ''
22
+ return chat_history_state, chat_message
23
+
24
+
25
+ def user(message, history):
26
+ history = history or []
27
+ # Append the user's message to the conversation history
28
+ history.append([message, ""])
29
+ return "", history
30
+
31
+
32
+ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
33
+ history = history or []
34
+
35
+ messages = "<|im_start|>"+"system\n" + BASE_SYSTEM_MESSAGE + system_message.strip() + "<|im_end|>\n" + \
36
+ "\n".join(["\n".join(["<|im_start|>"+"user\n"+item[0]+"<|im_end|>", "<|im_start|>assistant\n"+item[1]+"<|im_end|>"])
37
+ for item in history])
38
+ # strip the last `<|end_of_turn|>` from the messages
39
+ messages = messages.rstrip("<|im_end|>")
40
+ # remove last space from assistant, some models output a ZWSP if you leave a space
41
+ messages = messages.rstrip()
42
+
43
+ prediction = make_prediction(
44
+ messages,
45
+ max_tokens=max_tokens,
46
+ temperature=temperature,
47
+ top_p=top_p,
48
+ top_k=top_k,
49
+ repetition_penalty=repetition_penalty,
50
+ )
51
+ for tokens in prediction:
52
+ tokens = re.findall(r'(.*?)(\s|$)', tokens)
53
+ for subtoken in tokens:
54
+ subtoken = "".join(subtoken)
55
+ answer = subtoken
56
+ history[-1][1] += answer
57
+ # stream the response
58
+ yield history, history, ""
59
+
60
+
61
+ start_message = ""
62
+
63
+ CSS ="""
64
+ .contain { display: flex; flex-direction: column; }
65
+ .gradio-container { height: 100vh !important; }
66
+ #component-0 { height: 100%; }
67
+ #chatbot { flex-grow: 1; overflow: auto; resize: vertical; }
68
+ """
69
+
70
+ #with gr.Blocks() as demo:
71
+ with gr.Blocks(css=CSS) as demo:
72
+ with gr.Row():
73
+ with gr.Column():
74
+ gr.Markdown(f"""
75
+ ## This demo is an unquantized GPU chatbot of [OpenOrca LlongOrca-7B-16k](https://huggingface.co/Open-Orca/LlongOrca-7B-16k)
76
+ Brought to you by your friends at Alignment Lab AI, OpenChat, and Open Access AI Collective!
77
+ """)
78
+ with gr.Row():
79
+ gr.Markdown("# 🐋 OpenOrca LlongOrca-7B-16k Playground Space! 🐋")
80
+ with gr.Row():
81
+ #chatbot = gr.Chatbot().style(height=500)
82
+ chatbot = gr.Chatbot(elem_id="chatbot")
83
+ with gr.Row():
84
+ message = gr.Textbox(
85
+ label="What do you want to chat about?",
86
+ placeholder="Ask me anything.",
87
+ lines=3,
88
+ )
89
+ with gr.Row():
90
+ submit = gr.Button(value="Send message", variant="secondary").style(full_width=True)
91
+ clear = gr.Button(value="New topic", variant="secondary").style(full_width=False)
92
+ stop = gr.Button(value="Stop", variant="secondary").style(full_width=False)
93
+ with gr.Accordion("Show Model Parameters", open=False):
94
+ with gr.Row():
95
+ with gr.Column():
96
+ max_tokens = gr.Slider(20, 1000, label="Max Tokens", step=20, value=500)
97
+ temperature = gr.Slider(0.2, 2.0, label="Temperature", step=0.1, value=0.8)
98
+ top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.95)
99
+ top_k = gr.Slider(0, 100, label="Top K", step=1, value=40)
100
+ repetition_penalty = gr.Slider(0.0, 2.0, label="Repetition Penalty", step=0.1, value=1.1)
101
+
102
+ system_msg = gr.Textbox(
103
+ start_message, label="System Message", interactive=True, visible=True, placeholder="System prompt. Provide instructions which you want the model to remember.", lines=5)
104
+
105
+ chat_history_state = gr.State()
106
+ clear.click(clear_chat, inputs=[chat_history_state, message], outputs=[chat_history_state, message], queue=False)
107
+ clear.click(lambda: None, None, chatbot, queue=False)
108
+
109
+ submit_click_event = submit.click(
110
+ fn=user, inputs=[message, chat_history_state], outputs=[message, chat_history_state], queue=True
111
+ ).then(
112
+ fn=chat, inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot, chat_history_state, message], queue=True
113
+ )
114
+ stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event], queue=False)
115
+
116
+ demo.queue(max_size=128, concurrency_count=48).launch(debug=True, server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ requests
2
+ openai