hc1608 commited on
Commit
549e7ea
·
verified ·
1 Parent(s): c4cbc66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
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("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
 
9
 
10
  def respond(
11
  message,
@@ -25,20 +29,15 @@ def respond(
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
  temperature=temperature,
35
  top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
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
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
 
4
+ # Initialize OpenAI client
5
+ token = "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"
6
+ endpoint = "https://models.github.ai/inference"
7
+ model = "openai/gpt-4.1"
8
 
9
+ client = OpenAI(
10
+ base_url=endpoint,
11
+ api_key=token,
12
+ )
13
 
14
  def respond(
15
  message,
 
29
 
30
  messages.append({"role": "user", "content": message})
31
 
32
+ response = client.chat.completions.create(
33
+ messages=messages,
 
 
 
 
34
  temperature=temperature,
35
  top_p=top_p,
36
+ model=model,
37
+ max_tokens=max_tokens
38
+ )
 
 
39
 
40
+ return response.choices[0].message.content
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface