Teresatree commited on
Commit
d9e1f44
·
verified ·
1 Parent(s): 47e0f8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
-
5
  def respond(
6
  message,
7
  history: list[dict[str, str]],
@@ -14,16 +13,17 @@ def respond(
14
  """
15
  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
16
  """
17
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
 
18
 
 
19
  messages = [{"role": "system", "content": system_message}]
20
-
21
  messages.extend(history)
22
-
23
  messages.append({"role": "user", "content": message})
24
 
25
  response = ""
26
 
 
27
  for message in client.chat_completion(
28
  messages,
29
  max_tokens=max_tokens,
@@ -40,9 +40,7 @@ def respond(
40
  yield response
41
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  chatbot = gr.ChatInterface(
47
  respond,
48
  type="messages",
@@ -60,11 +58,11 @@ chatbot = gr.ChatInterface(
60
  ],
61
  )
62
 
 
63
  with gr.Blocks() as demo:
64
  with gr.Sidebar():
65
- gr.LoginButton()
66
  chatbot.render()
67
 
68
-
69
  if __name__ == "__main__":
70
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  def respond(
5
  message,
6
  history: list[dict[str, str]],
 
13
  """
14
  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
15
  """
16
+ # Use the correct ERNIE model
17
+ client = InferenceClient(token=hf_token.token, model="baidu/ERNIE-4.5-VL-28B-A3B-PT") # <-- Update this line with the desired model name
18
 
19
+ # Prepare the conversation history
20
  messages = [{"role": "system", "content": system_message}]
 
21
  messages.extend(history)
 
22
  messages.append({"role": "user", "content": message})
23
 
24
  response = ""
25
 
26
+ # Streaming response handling
27
  for message in client.chat_completion(
28
  messages,
29
  max_tokens=max_tokens,
 
40
  yield response
41
 
42
 
43
+ # Gradio chatbot interface setup
 
 
44
  chatbot = gr.ChatInterface(
45
  respond,
46
  type="messages",
 
58
  ],
59
  )
60
 
61
+ # Set up the Gradio Blocks interface
62
  with gr.Blocks() as demo:
63
  with gr.Sidebar():
64
+ gr.LoginButton() # Allows Hugging Face login
65
  chatbot.render()
66
 
 
67
  if __name__ == "__main__":
68
  demo.launch()