Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,19 @@
|
|
| 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=
|
| 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
|
| 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 |
-
|
| 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)
|
|
|