Saffn commited on
Commit
5e305bf
·
verified ·
1 Parent(s): 3871603

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,17 +1,14 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # --- Response function ---
5
- def respond(message, history, system_message, max_tokens, temperature, top_p, hf_token_info):
6
  """
7
- Handles streaming responses from Hugging Face Inference API.
8
- `hf_token_info` comes from LoginButton: hf_token_info['access_token']
9
  """
10
- if not hf_token_info or "access_token" not in hf_token_info:
11
- yield "Error: You must log in with your Hugging Face token."
12
  return
13
 
14
- hf_token = hf_token_info["access_token"]
15
  client = InferenceClient(token=hf_token, model="openai/gpt-oss-20b")
16
 
17
  messages = [{"role": "system", "content": system_message}]
@@ -36,8 +33,12 @@ def respond(message, history, system_message, max_tokens, temperature, top_p, hf
36
  # --- Gradio UI ---
37
  with gr.Blocks() as demo:
38
  with gr.Sidebar():
39
- gr.Markdown("## Hugging Face Login & Chatbot Settings")
40
- login_btn = gr.LoginButton("Log in with Hugging Face", provider="huggingface")
 
 
 
 
41
  system_message = gr.Textbox(
42
  value="You are a friendly Chatbot.",
43
  label="System message"
@@ -59,7 +60,7 @@ with gr.Blocks() as demo:
59
 
60
  msg.submit(
61
  respond,
62
- inputs=[msg, state, system_message, max_tokens, temperature, top_p, login_btn],
63
  outputs=[chatbot],
64
  show_progress=True
65
  )
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ def respond(message, history, system_message, max_tokens, temperature, top_p, hf_token):
 
5
  """
6
+ Streaming responses from Hugging Face Inference API
 
7
  """
8
+ if not hf_token:
9
+ yield "Error: Please provide your Hugging Face token."
10
  return
11
 
 
12
  client = InferenceClient(token=hf_token, model="openai/gpt-oss-20b")
13
 
14
  messages = [{"role": "system", "content": system_message}]
 
33
  # --- Gradio UI ---
34
  with gr.Blocks() as demo:
35
  with gr.Sidebar():
36
+ gr.Markdown("## Chatbot Settings")
37
+ hf_token = gr.Textbox(
38
+ placeholder="Paste your Hugging Face token here",
39
+ label="Hugging Face Token",
40
+ type="password"
41
+ )
42
  system_message = gr.Textbox(
43
  value="You are a friendly Chatbot.",
44
  label="System message"
 
60
 
61
  msg.submit(
62
  respond,
63
+ inputs=[msg, state, system_message, max_tokens, temperature, top_p, hf_token],
64
  outputs=[chatbot],
65
  show_progress=True
66
  )