Spaces:
Runtime error
Runtime error
zhangtao103239
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -26,19 +31,19 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
"""
|
43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
+
from llama_cpp import Llama
|
3 |
+
import requests
|
4 |
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
llm = Llama.from_pretrained(
|
7 |
+
repo_id="cognitivecomputations/dolphin-2.9.2-qwen2-7b-gguf",
|
8 |
+
filename="*Q4_K_S.gguf",
|
9 |
+
verbose=True,
|
10 |
+
n_ctx=32768,
|
11 |
+
n_threads=2,
|
12 |
+
chat_format="chatml"
|
13 |
+
)
|
14 |
|
15 |
def respond(
|
16 |
message,
|
|
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
|
33 |
response = ""
|
34 |
+
response = llm.create_chat_completion(
|
35 |
+
messages=messages,
|
36 |
+
stream=True,
|
37 |
+
max_tokens=max_tokens,
|
38 |
+
temperature=temperature,
|
39 |
+
top_p=top_p
|
40 |
+
)
|
41 |
+
message_repl = ""
|
42 |
+
for chunk in response:
|
43 |
+
if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
|
44 |
+
message_repl = message_repl + \
|
45 |
+
chunk['choices'][0]["delta"]["content"]
|
46 |
+
yield message_repl
|
47 |
"""
|
48 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
49 |
"""
|