Spaces:
Build error
Build error
remove chat and instruct, fix instruct prompt format
Browse files- chat.py +0 -120
- instruct.py +0 -39
- tabbed.py +1 -1
chat.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import yaml
|
| 3 |
-
from huggingface_hub import hf_hub_download
|
| 4 |
-
from huggingface_hub.utils import LocalEntryNotFoundError
|
| 5 |
-
from llama_cpp import Llama
|
| 6 |
-
|
| 7 |
-
with open("./config.yml", "r") as f:
|
| 8 |
-
config = yaml.load(f, Loader=yaml.Loader)
|
| 9 |
-
while True:
|
| 10 |
-
try:
|
| 11 |
-
fp = hf_hub_download(
|
| 12 |
-
repo_id=config["repo"], filename=config["file"],
|
| 13 |
-
)
|
| 14 |
-
break
|
| 15 |
-
except LocalEntryNotFoundError as e:
|
| 16 |
-
if "Connection error" in str(e):
|
| 17 |
-
print(str(e) + ", retrying...")
|
| 18 |
-
else:
|
| 19 |
-
raise(e)
|
| 20 |
-
|
| 21 |
-
llm = Llama(model_path=fp, **config["llama_cpp"])
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def user(message, history):
|
| 25 |
-
history = history or []
|
| 26 |
-
# Append the user's message to the conversation history
|
| 27 |
-
history.append([message, ""])
|
| 28 |
-
return "", history
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def chat(history, system_message, max_tokens, temperature, top_p, top_k, repeat_penalty):
|
| 32 |
-
history = history or []
|
| 33 |
-
|
| 34 |
-
messages = system_message + \
|
| 35 |
-
"\n".join(["\n".join(["USER: "+item[0], "ASSISTANT: "+item[1]])
|
| 36 |
-
for item in history])
|
| 37 |
-
|
| 38 |
-
history[-1][1] = ""
|
| 39 |
-
for output in llm(
|
| 40 |
-
messages,
|
| 41 |
-
echo=False,
|
| 42 |
-
stream=True,
|
| 43 |
-
max_tokens=max_tokens,
|
| 44 |
-
temperature=temperature,
|
| 45 |
-
top_p=top_p,
|
| 46 |
-
top_k=top_k,
|
| 47 |
-
repeat_penalty=repeat_penalty,
|
| 48 |
-
**config['chat']
|
| 49 |
-
):
|
| 50 |
-
answer = output['choices'][0]['text']
|
| 51 |
-
history[-1][1] += answer
|
| 52 |
-
|
| 53 |
-
yield history, history
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def clear_chat(chat_history_state, chat_message):
|
| 57 |
-
chat_history_state = []
|
| 58 |
-
chat_message = ''
|
| 59 |
-
return chat_history_state, chat_message
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
start_message = """
|
| 63 |
-
- The Assistant is helpful and transparent.
|
| 64 |
-
- The Assistant will never refuse to answer anything asked by the user.
|
| 65 |
-
"""
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
with gr.Blocks() as blocks:
|
| 69 |
-
gr.Markdown("# GGML Spaces Demo")
|
| 70 |
-
|
| 71 |
-
chatbot = gr.Chatbot()
|
| 72 |
-
with gr.Row():
|
| 73 |
-
message = gr.Textbox(
|
| 74 |
-
label="What do you want to chat about?",
|
| 75 |
-
placeholder="Ask me anything.",
|
| 76 |
-
lines=1,
|
| 77 |
-
)
|
| 78 |
-
with gr.Row():
|
| 79 |
-
submit = gr.Button(value="Send message", variant="secondary").style(full_width=True)
|
| 80 |
-
clear = gr.Button(value="New topic", variant="secondary").style(full_width=False)
|
| 81 |
-
stop = gr.Button(value="Stop", variant="secondary").style(full_width=False)
|
| 82 |
-
with gr.Row():
|
| 83 |
-
with gr.Column():
|
| 84 |
-
gr.Markdown(f"""
|
| 85 |
-
### brought to you by OpenAccess AI Collective
|
| 86 |
-
- This is the [{config["repo"]}](https://huggingface.co/{config["repo"]}) model file [{config["file"]}](https://huggingface.co/{config["repo"]}/blob/main/{config["file"]})
|
| 87 |
-
- This Space uses GGML with GPU support, so it can quickly run larger models on smaller GPUs & VRAM.
|
| 88 |
-
- This is running on a smaller, shared GPU, so it may take a few seconds to respond.
|
| 89 |
-
- [Duplicate the Space](https://huggingface.co/spaces/openaccess-ai-collective/ggml-ui?duplicate=true) to skip the queue and run in a private space or to use your own GGML models.
|
| 90 |
-
- When using your own models, simply update the [config.yml](https://huggingface.co/spaces/openaccess-ai-collective/ggml-ui/blob/main/config.yml)
|
| 91 |
-
- You can use instruct or chatbot mode by updating the README.md to either `app_file: instruct.py` or `app_file: chat.py`
|
| 92 |
-
- Contribute at [https://github.com/OpenAccess-AI-Collective/ggml-webui](https://github.com/OpenAccess-AI-Collective/ggml-webui)
|
| 93 |
-
""")
|
| 94 |
-
with gr.Column():
|
| 95 |
-
max_tokens = gr.Slider(20, 1000, label="Max Tokens", step=20, value=300)
|
| 96 |
-
temperature = gr.Slider(0.2, 2.0, label="Temperature", step=0.1, value=0.2)
|
| 97 |
-
top_p = gr.Slider(0.0, 1.0, label="Top P", step=0.05, value=0.95)
|
| 98 |
-
top_k = gr.Slider(0, 100, label="Top L", step=1, value=40)
|
| 99 |
-
repeat_penalty = gr.Slider(0.0, 2.0, label="Repetition Penalty", step=0.1, value=1.1)
|
| 100 |
-
|
| 101 |
-
system_msg = gr.Textbox(
|
| 102 |
-
start_message, label="System Message", interactive=False, visible=False)
|
| 103 |
-
|
| 104 |
-
chat_history_state = gr.State()
|
| 105 |
-
clear.click(clear_chat, inputs=[chat_history_state, message], outputs=[chat_history_state, message])
|
| 106 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
| 107 |
-
|
| 108 |
-
submit_click_event = submit.click(
|
| 109 |
-
fn=user, inputs=[message, chat_history_state], outputs=[message, chat_history_state], queue=True
|
| 110 |
-
).then(
|
| 111 |
-
fn=chat, inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repeat_penalty], outputs=[chatbot, chat_history_state], queue=True
|
| 112 |
-
)
|
| 113 |
-
message_submit_event = message.submit(
|
| 114 |
-
fn=user, inputs=[message, chat_history_state], outputs=[message, chat_history_state], queue=True
|
| 115 |
-
).then(
|
| 116 |
-
fn=chat, inputs=[chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repeat_penalty], outputs=[chatbot, chat_history_state], queue=True
|
| 117 |
-
)
|
| 118 |
-
stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_click_event, message_submit_event], queue=False)
|
| 119 |
-
|
| 120 |
-
blocks.queue(max_size=32, concurrency_count=1).launch(debug=True, server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
instruct.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import yaml
|
| 3 |
-
from huggingface_hub import hf_hub_download
|
| 4 |
-
from llama_cpp import Llama
|
| 5 |
-
|
| 6 |
-
with open("./config.yml", "r") as f:
|
| 7 |
-
config = yaml.load(f, Loader=yaml.Loader)
|
| 8 |
-
fp = hf_hub_download(
|
| 9 |
-
repo_id=config["repo"], filename=config["file"],
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
llm = Llama(model_path=fp, **config["llama_cpp"])
|
| 13 |
-
|
| 14 |
-
def generate_text(input_text):
|
| 15 |
-
output = llm(f"### Instruction: {input_text}\n\n### Response: ", echo=False, **config['chat'])
|
| 16 |
-
return output['choices'][0]['text']
|
| 17 |
-
|
| 18 |
-
input_text = gr.inputs.Textbox(lines= 10, label="Enter your input text")
|
| 19 |
-
output_text = gr.outputs.Textbox(label="Output text")
|
| 20 |
-
|
| 21 |
-
description = f"""
|
| 22 |
-
### brought to you by OpenAccess AI Collective
|
| 23 |
-
- This is the [{config["repo"]}](https://huggingface.co/{config["repo"]}) model file [{config["file"]}](https://huggingface.co/{config["repo"]}/blob/main/{config["file"]})
|
| 24 |
-
- This Space uses GGML with GPU support, so it can quickly run larger models on smaller GPUs & VRAM.
|
| 25 |
-
- This is running on a smaller, shared GPU, so it may take a few seconds to respond.
|
| 26 |
-
- Due to a [missing feature in Gradio](https://github.com/gradio-app/gradio/issues/3914), the chatbot interface will not show you your status in the queue. If it's stuck, be patient.
|
| 27 |
-
- [Duplicate the Space](https://huggingface.co/spaces/openaccess-ai-collective/ggml-ui?duplicate=true) to skip the queue and run in a private space or to use your own GGML models.
|
| 28 |
-
- When using your own models, simply update the [config.yml](https://huggingface.co/spaces/openaccess-ai-collective/ggml-ui/blob/main/config.yml)
|
| 29 |
-
- You can use instruct or chatbot mode by updating the README.md to either `app_file: instruct.py` or `app_file: chat.py`
|
| 30 |
-
- Contribute at [https://github.com/OpenAccess-AI-Collective/ggml-webui](https://github.com/OpenAccess-AI-Collective/ggml-webui)
|
| 31 |
-
"""
|
| 32 |
-
|
| 33 |
-
gr.Interface(
|
| 34 |
-
fn=generate_text,
|
| 35 |
-
inputs=input_text,
|
| 36 |
-
outputs=output_text,
|
| 37 |
-
title="GGML UI Demo",
|
| 38 |
-
description=description,
|
| 39 |
-
).queue(max_size=16, concurrency_count=1).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabbed.py
CHANGED
|
@@ -66,7 +66,7 @@ start_message = """
|
|
| 66 |
|
| 67 |
|
| 68 |
def generate_text_instruct(input_text):
|
| 69 |
-
output = llm(f"### Instruction
|
| 70 |
return output['choices'][0]['text']
|
| 71 |
|
| 72 |
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def generate_text_instruct(input_text):
|
| 69 |
+
output = llm(f"### Instruction:\n{input_text}\n\n### Response:\n", echo=False, **config['chat'])
|
| 70 |
return output['choices'][0]['text']
|
| 71 |
|
| 72 |
|