Freddy Boulton commited on
Commit
3eb4b38
·
1 Parent(s): 8d610eb
Files changed (2) hide show
  1. README.md +3 -0
  2. app.py +13 -3
README.md CHANGED
@@ -7,6 +7,9 @@ sdk: gradio
7
  sdk_version: 5.42.0
8
  app_file: app.py
9
  pinned: false
 
 
 
10
  ---
11
 
12
  An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
7
  sdk_version: 5.42.0
8
  app_file: app.py
9
  pinned: false
10
+ hf_oauth: true
11
+ hf_oauth_scopes:
12
+ - inference-api
13
  ---
14
 
15
  An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
app.py CHANGED
@@ -4,7 +4,6 @@ from huggingface_hub import InferenceClient
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(model="openai/gpt-oss-20b", provider="auto")
8
 
9
 
10
  def respond(
@@ -14,7 +13,9 @@ def respond(
14
  max_tokens,
15
  temperature,
16
  top_p,
 
17
  ):
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
@@ -34,7 +35,10 @@ def respond(
34
  temperature=temperature,
35
  top_p=top_p,
36
  ):
37
- token = message.choices[0].delta.content
 
 
 
38
 
39
  response += token
40
  yield response
@@ -43,8 +47,9 @@ def respond(
43
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
  """
46
- demo = gr.ChatInterface(
47
  respond,
 
48
  additional_inputs=[
49
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
@@ -59,6 +64,11 @@ demo = gr.ChatInterface(
59
  ],
60
  )
61
 
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
  demo.launch()
 
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
 
8
 
9
  def respond(
 
13
  max_tokens,
14
  temperature,
15
  top_p,
16
+ hf_token: gr.OAuthToken,
17
  ):
18
+ client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
19
  messages = [{"role": "system", "content": system_message}]
20
 
21
  for val in history:
 
35
  temperature=temperature,
36
  top_p=top_p,
37
  ):
38
+ choices = message.choices
39
+ token = ""
40
+ if len(choices) and choices[0].delta.content:
41
+ token = choices[0].delta.content
42
 
43
  response += token
44
  yield response
 
47
  """
48
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
49
  """
50
+ chatbot = gr.ChatInterface(
51
  respond,
52
+ type="messages",
53
  additional_inputs=[
54
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
55
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
64
  ],
65
  )
66
 
67
+ with gr.Blocks() as demo:
68
+ with gr.Sidebar():
69
+ gr.LoginButton()
70
+ chatbot.render()
71
+
72
 
73
  if __name__ == "__main__":
74
  demo.launch()