Spaces:
Sleeping
Sleeping
import os | |
import json | |
import gradio as gr | |
from llama_cpp import Llama | |
title = "Explore the Power of WestLake-7B: Advanced Conversational AI" | |
description = """ | |
Welcome to the WestLake-7B Chat experience! Dive into the realm of advanced conversational AI with our cutting-edge model, WestLake-7B. | |
This model, designed for nuanced and intelligent conversation, represents a significant leap in language processing capabilities. | |
Explore its features and witness the future of AI-driven communication. | |
Get your hands on the model and more details by clicking here: <a href="https://huggingface.co/senseable/Westlake-7B-gguf/">Westlake-7B on Hugging Face</a>. | |
""" | |
llm = Llama(model_path="model.gguf", | |
n_ctx=32768, | |
n_threads=2, | |
chat_format="chatml") | |
def chat_stream_completion(message, history, system_prompt): | |
messages_prompts = [{"role": "system", "content": system_prompt}] | |
for human, assistant in history: | |
messages_prompts.append({"role": "user", "content": human}) | |
messages_prompts.append({"role": "assistant", "content": assistant}) | |
messages_prompts.append({"role": "user", "content": message}) | |
response = llm.create_chat_completion( | |
messages=messages_prompts, | |
stream=True | |
) | |
message_repl = "" | |
for chunk in response: | |
if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]: | |
message_repl = message_repl + chunk['choices'][0]["delta"]["content"] | |
yield message_repl | |
gr.ChatInterface( | |
fn=chat_stream_completion, | |
title=title, | |
description=description, | |
additional_inputs=[gr.Textbox("Perform the task to the best of your ability.")], | |
additional_inputs_accordion="π System prompt", | |
examples=[ | |
["Summarize the key themes of '1984' by George Orwell."], | |
["Convert 150 Fahrenheit to Celsius."], | |
["Generate a short story about a time-traveling detective."], | |
["Explain the concept of black holes in simple terms."], | |
["What are the health benefits of Mediterranean diet?"], | |
["Write Python code to sort a list of numbers in ascending order."], | |
["Translate 'Hello, how are you?' into French."], | |
["Create a motivational quote about perseverance."] | |
] | |
).queue().launch(server_name="0.0.0.0") |