import gradio as gr from huggingface_hub import InferenceClient def respond(message, history, system_message, max_tokens, temperature, top_p, hf_token): client = InferenceClient(token=hf_token, model="openai/gpt-oss-20b") messages = [{"role": "system", "content": system_message}] + history messages.append({"role": "user", "content": message}) response = "" for message in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p ): token = message.choices[0].delta.content if message.choices and message.choices[0].delta.content else "" response += token yield response chatbot = gr.ChatInterface( respond, type="messages", additional_inputs=[ gr.Textbox(value="You are a friendly Chatbot.", label="System message"), gr.Slider(1, 2048, value=512, step=1, label="Max new tokens"), gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"), gr.Textbox(value="hf_YourTokenHere", label="HF Token") ], ) if __name__ == "__main__": # This will launch both a web UI and a programmatic endpoint chatbot.launch(share=True)