Spaces:
Sleeping
Sleeping
File size: 1,506 Bytes
f1f3641 9b5b26a f1f3641 89dbda5 8c01ffb f1f3641 8564a64 0172db2 f1f3641 8c01ffb f1f3641 89dbda5 f1f3641 0172db2 f1f3641 0172db2 9cf0b72 f1f3641 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import llama_cpp
import llama_cpp.llama_tokenizer
import gradio as gr
llama = llama_cpp.Llama.from_pretrained(
repo_id="Qwen/Qwen1.5-0.5B-Chat-GGUF",
filename="*q8_0.gguf",
tokenizer=llama_cpp.llama_tokenizer.LlamaHFTokenizer.from_pretrained(
"Qwen/Qwen1.5-0.5B"
),
verbose=False,
)
model = "gpt-3.5-turbo"
def predict(message, history):
messages = []
for user_message, assistant_message in history:
messages.append({"role": "user", "content": user_message})
messages.append({"role": "assistant", "content": assistant_message})
messages.append({"role": "user", "content": message})
response = llama.create_chat_completion_openai_v1(
model=model, messages=messages, stream=True
)
text = ""
for chunk in response:
content = chunk.choices[0].delta.content
if content:
text += content
yield text
js = """function () {
gradioURL = window.location.href
if (!gradioURL.endsWith('?__theme=dark')) {
window.location.replace(gradioURL + '?__theme=dark');
}
}"""
css = """
footer {
visibility: hidden;
}
full-height {
height: 100%;
}
"""
with gr.Blocks(theme=gr.themes.Soft(), js=js, css=css, fill_height=True) as demo:
gr.ChatInterface(
predict,
fill_height=True,
examples=[
"What is the capital of France?",
"Who was the first person on the moon?",
],
)
if __name__ == "__main__":
demo.launch() |