muhammad1707 commited on
Commit
868a055
·
1 Parent(s): 28a55bd

added hf token and updated app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -12
app.py CHANGED
@@ -1,25 +1,24 @@
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
 
5
  def respond(
6
  message,
7
- history: list[dict[str, str]],
8
  system_message,
9
  max_tokens,
10
  temperature,
11
  top_p,
12
- hf_token: gr.OAuthToken,
13
  ):
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 = ""
@@ -38,6 +37,42 @@ def respond(
38
 
39
  response += token
40
  yield response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  """
@@ -60,10 +95,10 @@ 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__":
 
1
+ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
 
6
  def respond(
7
  message,
8
+ history,
9
  system_message,
10
  max_tokens,
11
  temperature,
12
  top_p,
 
13
  ):
14
+ hf_token = os.getenv("HF_TOKEN")
15
+ client = InferenceClient(
16
+ token=hf_token,
17
+ model="openai/gpt-oss-20b"
18
+ )
19
 
20
  messages = [{"role": "system", "content": system_message}]
 
21
  messages.extend(history)
 
22
  messages.append({"role": "user", "content": message})
23
 
24
  response = ""
 
37
 
38
  response += token
39
  yield response
40
+ # def respond(
41
+ # message,
42
+ # history: list[dict[str, str]],
43
+ # system_message,
44
+ # max_tokens,
45
+ # temperature,
46
+ # top_p,
47
+ # hf_token: gr.OAuthToken,
48
+ # ):
49
+ # """
50
+ # 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
51
+ # """
52
+ # client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
53
+
54
+ # messages = [{"role": "system", "content": system_message}]
55
+
56
+ # messages.extend(history)
57
+
58
+ # messages.append({"role": "user", "content": message})
59
+
60
+ # response = ""
61
+
62
+ # for message in client.chat_completion(
63
+ # messages,
64
+ # max_tokens=max_tokens,
65
+ # stream=True,
66
+ # temperature=temperature,
67
+ # top_p=top_p,
68
+ # ):
69
+ # choices = message.choices
70
+ # token = ""
71
+ # if len(choices) and choices[0].delta.content:
72
+ # token = choices[0].delta.content
73
+
74
+ # response += token
75
+ # yield response
76
 
77
 
78
  """
 
95
  ],
96
  )
97
 
98
+ # with gr.Blocks() as demo:
99
+ # with gr.Sidebar():
100
+ # gr.LoginButton()
101
+ # chatbot.render()
102
 
103
 
104
  if __name__ == "__main__":