File size: 841 Bytes
cfbebb6
 
c2ef56b
8cf42f3
cfbebb6
 
8cf42f3
cfbebb6
 
8cf42f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfbebb6
8cf42f3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
from openai import OpenAI
import os
# Initialize the Hugging Face API client
client = OpenAI(
    base_url="https://router.huggingface.co/v1",
    api_key= os.getenv("HF_TOKEN")
)

# Function to interact with the model
def chat_with_model(user_input):
    completion = client.chat.completions.create(
        model="openai/gpt-oss-20b:nebius",
        messages=[
            {"role": "user", "content": user_input}
        ],
    )
    return completion.choices[0].message['content']

# Gradio interface
iface = gr.Interface(
    fn=chat_with_model,
    inputs=gr.Textbox(lines=5, placeholder="Type your message here..."),
    outputs=gr.Textbox(label="Response"),
    title="Hugging Face GPT-OSS Chat",
    description="Chat with GPT-OSS 20B model deployed via Hugging Face API"
)

# Launch the interface
iface.launch()