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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -4,9 +4,7 @@ from huggingface_hub import InferenceClient
4
  MODEL = "mlabonne/gemma-3-27b-it-abliterated:featherless-ai"
5
  SYSTEM_PROMPT = """
6
  You are an erotic writer assistant, who responds to the user requests in plain text, not markdown
7
-
8
  Your responses are very short and direct
9
-
10
  Your responses must be worded as if they were the statistics in an RPG game, with item and character descriptions as if they were part of the game
11
  """
12
  DEFAULT_TOKENS = 300
@@ -24,30 +22,27 @@ def respond(
24
  hf_token: gr.OAuthToken,
25
  ):
26
  """
27
- 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
28
- """
29
  client = InferenceClient(token=hf_token.token, model=MODEL)
30
 
31
  messages = [{"role": "system", "content": system_message}]
32
  messages.extend(history)
33
  messages.append({"role": "user", "content": message})
34
-
35
- response = ""
36
- for message in client.chat_completion(
37
  messages,
38
  max_tokens=max_tokens,
39
- stream=True,
40
  temperature=temperature,
41
  top_p=top_p,
42
- ):
43
- choices = message.choices
44
- token = ""
45
- if len(choices) and choices[0].delta.content:
46
- token = choices[0].delta.content
47
 
48
- response += token
 
49
  yield response
50
 
 
51
  """
52
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
53
  """
@@ -56,8 +51,16 @@ chatbot = gr.ChatInterface(
56
  type="messages",
57
  additional_inputs=[
58
  gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
59
- gr.Slider(minimum=1, maximum=2048, value=DEFAULT_TOKENS, step=1, label="Max new tokens"),
60
- gr.Slider(minimum=0.1, maximum=4.0, value=DEFAULT_TEMPERATURE, step=0.1, label="Temperature"),
 
 
 
 
 
 
 
 
61
  gr.Slider(
62
  minimum=0.1,
63
  maximum=1.0,
@@ -66,12 +69,15 @@ chatbot = gr.ChatInterface(
66
  label="Top-p (nucleus sampling)",
67
  ),
68
  ],
69
- #examples=[
70
- # [
71
- # "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",
72
- # SYSTEM_PROMPT, DEFAULT_TOKENS, DEFAULT_TEMPERATURE, DEFAULT_TOP_P,
73
- # ],
74
- #],
 
 
 
75
  )
76
 
77
  with gr.Blocks() as demo:
@@ -79,6 +85,5 @@ with gr.Blocks() as demo:
79
  gr.LoginButton()
80
  chatbot.render()
81
 
82
-
83
  if __name__ == "__main__":
84
  demo.launch(ssr_mode=False)
 
4
  MODEL = "mlabonne/gemma-3-27b-it-abliterated:featherless-ai"
5
  SYSTEM_PROMPT = """
6
  You are an erotic writer assistant, who responds to the user requests in plain text, not markdown
 
7
  Your responses are very short and direct
 
8
  Your responses must be worded as if they were the statistics in an RPG game, with item and character descriptions as if they were part of the game
9
  """
10
  DEFAULT_TOKENS = 300
 
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
  """
 
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,
 
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:
 
85
  gr.LoginButton()
86
  chatbot.render()
87
 
 
88
  if __name__ == "__main__":
89
  demo.launch(ssr_mode=False)