Muhammadidrees commited on
Commit
a7279ae
·
verified ·
1 Parent(s): c2ef56b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -1,23 +1,19 @@
1
  import gradio as gr
2
  from openai import OpenAI
3
  import os
4
- # Initialize the Hugging Face API client
5
  client = OpenAI(
6
  base_url="https://router.huggingface.co/v1",
7
- api_key= os.getenv("HF_TOKEN")
8
  )
9
 
10
- # Function to interact with the model
11
  def chat_with_model(user_input):
12
  completion = client.chat.completions.create(
13
  model="openai/gpt-oss-20b:nebius",
14
- messages=[
15
- {"role": "user", "content": user_input}
16
- ],
17
  )
18
- return completion.choices[0].message['content']
19
 
20
- # Gradio interface
21
  iface = gr.Interface(
22
  fn=chat_with_model,
23
  inputs=gr.Textbox(lines=5, placeholder="Type your message here..."),
@@ -26,5 +22,4 @@ iface = gr.Interface(
26
  description="Chat with GPT-OSS 20B model deployed via Hugging Face API"
27
  )
28
 
29
- # Launch the interface
30
- iface.launch()
 
1
  import gradio as gr
2
  from openai import OpenAI
3
  import os
4
+
5
  client = OpenAI(
6
  base_url="https://router.huggingface.co/v1",
7
+ api_key=os.getenv("HF_TOKEN")
8
  )
9
 
 
10
  def chat_with_model(user_input):
11
  completion = client.chat.completions.create(
12
  model="openai/gpt-oss-20b:nebius",
13
+ messages=[{"role": "user", "content": user_input}],
 
 
14
  )
15
+ return completion.choices[0].message.content
16
 
 
17
  iface = gr.Interface(
18
  fn=chat_with_model,
19
  inputs=gr.Textbox(lines=5, placeholder="Type your message here..."),
 
22
  description="Chat with GPT-OSS 20B model deployed via Hugging Face API"
23
  )
24
 
25
+ iface.launch(ssr_mode=False)