Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
from llama_cpp import Llama
|
5 |
+
|
6 |
+
title = "Explore the Power of WestLake-7B: Advanced Conversational AI"
|
7 |
+
description = """
|
8 |
+
Welcome to the WestLake-7B Chat experience! Dive into the realm of advanced conversational AI with our cutting-edge model, WestLake-7B.
|
9 |
+
This model, designed for nuanced and intelligent conversation, represents a significant leap in language processing capabilities.
|
10 |
+
Explore its features and witness the future of AI-driven communication.
|
11 |
+
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>.
|
12 |
+
"""
|
13 |
+
|
14 |
+
llm = Llama(model_path="model.gguf",
|
15 |
+
n_ctx=32768,
|
16 |
+
n_threads=2,
|
17 |
+
chat_format="chatml")
|
18 |
+
|
19 |
+
def chat_stream_completion(message, history, system_prompt):
|
20 |
+
messages_prompts = [{"role": "system", "content": system_prompt}]
|
21 |
+
for human, assistant in history:
|
22 |
+
messages_prompts.append({"role": "user", "content": human})
|
23 |
+
messages_prompts.append({"role": "assistant", "content": assistant})
|
24 |
+
messages_prompts.append({"role": "user", "content": message})
|
25 |
+
|
26 |
+
response = llm.create_chat_completion(
|
27 |
+
messages=messages_prompts,
|
28 |
+
stream=True
|
29 |
+
)
|
30 |
+
message_repl = ""
|
31 |
+
for chunk in response:
|
32 |
+
if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
|
33 |
+
message_repl = message_repl + chunk['choices'][0]["delta"]["content"]
|
34 |
+
yield message_repl
|
35 |
+
|
36 |
+
gr.ChatInterface(
|
37 |
+
fn=chat_stream_completion,
|
38 |
+
title=title,
|
39 |
+
description=description,
|
40 |
+
additional_inputs=[gr.Textbox("Perform the task to the best of your ability.")],
|
41 |
+
additional_inputs_accordion="📝 System prompt",
|
42 |
+
examples=[
|
43 |
+
["Summarize the key themes of '1984' by George Orwell."],
|
44 |
+
["Convert 150 Fahrenheit to Celsius."],
|
45 |
+
["Generate a short story about a time-traveling detective."],
|
46 |
+
["Explain the concept of black holes in simple terms."],
|
47 |
+
["What are the health benefits of Mediterranean diet?"],
|
48 |
+
["Write Python code to sort a list of numbers in ascending order."],
|
49 |
+
["Translate 'Hello, how are you?' into French."],
|
50 |
+
["Create a motivational quote about perseverance."]
|
51 |
+
]
|
52 |
+
|
53 |
+
).queue().launch(server_name="0.0.0.0")
|