zhangtao103239 commited on
Commit
b879a1f
1 Parent(s): c050391

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -1,11 +1,16 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
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
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
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
  """