Blue-kod commited on
Commit
ac41e61
·
verified ·
1 Parent(s): 600f6ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -29
app.py CHANGED
@@ -1,12 +1,17 @@
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("gai-labs/strela")
8
-
9
-
 
 
 
 
 
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,30 +20,22 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
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
+ import os
3
+ from gpt4all import GPT4All
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
+ model = GPT4All(model_name='strela-q4_k_m.gguf', model_path=os.getcwd())
8
+
9
+ def stop_on_token_callback(token_id, token_string):
10
+ print(token_string, end='')
11
+ if '#' in token_string:
12
+ return False
13
+ else:
14
+ return True
15
  def respond(
16
  message,
17
  history: list[tuple[str, str]],
 
20
  temperature,
21
  top_p,
22
  ):
23
+ chat = f"""### System:
24
+ {system_message}
25
+ """
26
+ for group in history:
27
+ chat += f"""### Human:
28
+ {group[0]}
29
+ ### Assistant:
30
+ {group[1]}"""
31
+ chat += f"""### Human:
32
+ {message}
33
+ ### Assistant:
34
+ """
35
+ tokens = ""
36
+ for token in model.generate(chat, temp=temperature, callback=stop_on_token_callback, streaming=True):
37
+ tokens += token
38
+ yield tokens
 
 
 
 
 
 
 
 
39
  """
40
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
41
  """