Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,15 @@ openai.api_key = os.environ.get("OPENAI_API_KEY")
|
|
10 |
|
11 |
BASE_SYSTEM_MESSAGE = """"""
|
12 |
|
13 |
-
def make_prediction(prompt, max_tokens=None, temperature=None, top_p=None, top_k=None, repetition_penalty=None):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
yield chunk["choices"][0]["text"]
|
22 |
|
23 |
|
@@ -45,7 +46,8 @@ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetit
|
|
45 |
# remove last space from assistant, some models output a ZWSP if you leave a space
|
46 |
messages = messages.rstrip()
|
47 |
|
48 |
-
|
|
|
49 |
messages,
|
50 |
max_tokens=max_tokens,
|
51 |
temperature=temperature,
|
@@ -53,7 +55,27 @@ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetit
|
|
53 |
top_k=top_k,
|
54 |
repetition_penalty=repetition_penalty,
|
55 |
)
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
tokens = re.findall(r'(.*?)(\s|$)', tokens)
|
58 |
for subtoken in tokens:
|
59 |
subtoken = "".join(subtoken)
|
@@ -82,7 +104,6 @@ with gr.Blocks(css=CSS) as demo:
|
|
82 |
with gr.Column():
|
83 |
gr.Markdown(f"""
|
84 |
## This demo is an unquantized GPU chatbot of [WizardCoder-Python-34B-V1.0-GGUF](https://huggingface.co/TheBloke/WizardCoder-Python-34B-V1.0-GGUF)
|
85 |
-
Brought to you by your friends at Alignment Lab AI, garage-bAInd, Open Access AI Collective, and OpenChat!
|
86 |
""")
|
87 |
with gr.Row():
|
88 |
gr.Markdown("# π WizardCoder-Python-34B-V1.0-GGUF Playground Space! π")
|
|
|
10 |
|
11 |
BASE_SYSTEM_MESSAGE = """"""
|
12 |
|
13 |
+
def make_prediction(chat, prompt, max_tokens=None, temperature=None, top_p=None, top_k=None, repetition_penalty=None):
|
14 |
+
if chat="Chatbot1":
|
15 |
+
openai.api_base = os.environ.get("OPENAI_API_BASE")
|
16 |
+
completion = openai.Completion.create(model="wizardcoder-python-34b-v1.0.Q5_K_M.gguf", 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|>"])
|
17 |
+
elif chat="Chatbot2":
|
18 |
+
openai.api_base = os.environ.get("OPENAI_API_BASE2")
|
19 |
+
completion = openai.Completion.create(model="wizardcoder-python-34b-v1.0.Q5_K_M.gguf", 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|>"])
|
20 |
+
|
21 |
+
for chunk in completion:
|
22 |
yield chunk["choices"][0]["text"]
|
23 |
|
24 |
|
|
|
46 |
# remove last space from assistant, some models output a ZWSP if you leave a space
|
47 |
messages = messages.rstrip()
|
48 |
|
49 |
+
prediction1 = make_prediction(
|
50 |
+
chat="Chatbot1",
|
51 |
messages,
|
52 |
max_tokens=max_tokens,
|
53 |
temperature=temperature,
|
|
|
55 |
top_k=top_k,
|
56 |
repetition_penalty=repetition_penalty,
|
57 |
)
|
58 |
+
prediction2 = = make_prediction(
|
59 |
+
chat="Chatbot1",
|
60 |
+
messages,
|
61 |
+
max_tokens=max_tokens,
|
62 |
+
temperature=temperature,
|
63 |
+
top_p=top_p,
|
64 |
+
top_k=top_k,
|
65 |
+
repetition_penalty=repetition_penalty,
|
66 |
+
)
|
67 |
+
for tokens in prediction1:
|
68 |
+
tokens = re.findall(r'(.*?)(\s|$)', tokens)
|
69 |
+
for subtoken in tokens:
|
70 |
+
subtoken = "".join(subtoken)
|
71 |
+
# Remove "Response\n" if it's at the beginning of the assistant's output
|
72 |
+
if subtoken.startswith("Response"):
|
73 |
+
subtoken = subtoken[len("Response"):]
|
74 |
+
answer = subtoken
|
75 |
+
history[-1][1] += answer
|
76 |
+
# stream the response
|
77 |
+
yield history, history, ""
|
78 |
+
for tokens in prediction2:
|
79 |
tokens = re.findall(r'(.*?)(\s|$)', tokens)
|
80 |
for subtoken in tokens:
|
81 |
subtoken = "".join(subtoken)
|
|
|
104 |
with gr.Column():
|
105 |
gr.Markdown(f"""
|
106 |
## This demo is an unquantized GPU chatbot of [WizardCoder-Python-34B-V1.0-GGUF](https://huggingface.co/TheBloke/WizardCoder-Python-34B-V1.0-GGUF)
|
|
|
107 |
""")
|
108 |
with gr.Row():
|
109 |
gr.Markdown("# π WizardCoder-Python-34B-V1.0-GGUF Playground Space! π")
|