DviantDses commited on
Commit
3019023
·
verified ·
1 Parent(s): 0945d5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -57
app.py CHANGED
@@ -13,77 +13,71 @@ DEFAULT_TOP_P = 0.95
13
 
14
 
15
  def respond(
16
- message,
17
- history: list[dict[str, str]],
18
- system_message,
19
- max_tokens,
20
- temperature,
21
- top_p,
22
- hf_token: gr.OAuthToken,
23
  ):
24
- """
25
  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
26
  """
27
- client = InferenceClient(token=hf_token.token, model=MODEL)
28
 
29
- messages = [{"role": "system", "content": system_message}]
30
- messages.extend(history)
31
- messages.append({"role": "user", "content": message})
32
 
33
- completion = client.chat_completion(
34
- messages,
35
- max_tokens=max_tokens,
36
- stream=False,
37
- temperature=temperature,
38
- top_p=top_p,
39
- )
40
 
41
- for choice in completion.choices:
42
- response = choice.message.content
43
- yield response
 
 
44
 
45
 
46
  """
47
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
48
  """
49
  chatbot = gr.ChatInterface(
50
- respond,
51
- type="messages",
52
- additional_inputs=[
53
- gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
54
- gr.Slider(minimum=1,
55
- maximum=2048,
56
- value=DEFAULT_TOKENS,
57
- step=1,
58
- label="Max new tokens"),
59
- gr.Slider(minimum=0.1,
60
- maximum=4.0,
61
- value=DEFAULT_TEMPERATURE,
62
- step=0.1,
63
- label="Temperature"),
64
- gr.Slider(
65
- minimum=0.1,
66
- maximum=1.0,
67
- value=DEFAULT_TOP_P,
68
- step=0.05,
69
- label="Top-p (nucleus sampling)",
70
- ),
71
- ],
72
- examples=[
73
- [
74
- "Provide the stats of the female workers in the local town's brothel, these stats refer to the number of sexual acts (vaginal, anal, etc) executed by each person and their profficiency at it",
75
- SYSTEM_PROMPT,
76
- DEFAULT_TOKENS,
77
- DEFAULT_TEMPERATURE,
78
- DEFAULT_TOP_P,
79
- ],
80
- ],
81
  )
82
 
83
  with gr.Blocks() as demo:
84
- with gr.Sidebar():
85
- gr.LoginButton()
86
- chatbot.render()
87
 
88
  if __name__ == "__main__":
89
- demo.launch(ssr_mode=False)
 
13
 
14
 
15
  def respond(
16
+ message,
17
+ history: list[dict[str, str]],
18
+ system_message,
19
+ max_tokens,
20
+ temperature,
21
+ top_p,
22
+ hf_token: gr.OAuthToken,
23
  ):
24
+ """
25
  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
26
  """
27
+ client = InferenceClient(token=hf_token.token, model=MODEL)
28
 
29
+ messages = [{"role": "system", "content": system_message}]
30
+ messages.extend(history)
31
+ messages.append({"role": "user", "content": message})
32
 
33
+ completion = client.chat_completion(
34
+ messages,
35
+ max_tokens=max_tokens,
36
+ stream=False,
37
+ temperature=temperature,
38
+ top_p=top_p,
39
+ )
40
 
41
+ for choice in completion.choices:
42
+ response = choice.message.content
43
+ if response:
44
+ response = response.replace("*", "").replace("_", "")
45
+ yield response
46
 
47
 
48
  """
49
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
50
  """
51
  chatbot = gr.ChatInterface(
52
+ respond,
53
+ type="messages",
54
+ additional_inputs=[
55
+ gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
56
+ gr.Slider(minimum=1, maximum=2048, value=DEFAULT_TOKENS, step=1, label="Max new tokens"),
57
+ gr.Slider(minimum=0.1, maximum=4.0, value=DEFAULT_TEMPERATURE, step=0.1, label="Temperature"),
58
+ gr.Slider(
59
+ minimum=0.1,
60
+ maximum=1.0,
61
+ value=DEFAULT_TOP_P,
62
+ step=0.05,
63
+ label="Top-p (nucleus sampling)",
64
+ ),
65
+ ],
66
+ # examples=[
67
+ # [
68
+ # "Provide the stats of the female workers in the local town's brothel, these stats refer to the number of sexual acts (vaginal, anal, etc) executed by each person and their profficiency at it",
69
+ # SYSTEM_PROMPT,
70
+ # DEFAULT_TOKENS,
71
+ # DEFAULT_TEMPERATURE,
72
+ # DEFAULT_TOP_P,
73
+ # ],
74
+ # ],
 
 
 
 
 
 
 
 
75
  )
76
 
77
  with gr.Blocks() as demo:
78
+ with gr.Sidebar():
79
+ gr.LoginButton()
80
+ chatbot.render()
81
 
82
  if __name__ == "__main__":
83
+ demo.launch(ssr_mode=False, )