import gradio as gr from huggingface_hub import InferenceClient HF_TOKEN = "hf_your_access_token_here" # Replace with your HF API token def respond(message, history, system_message, max_tokens, temperature, top_p): client = InferenceClient( token=HF_TOKEN, model="Nikolester0/Gyaanchand-3B", ) messages = [{"role": "system", "content": system_message}] messages.extend(history) messages.append({"role": "user", "content": message}) response = "" for chunk in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): choices = chunk.choices if len(choices) and choices[0].delta.content: response += choices[0].delta.content yield response chatbot = gr.ChatInterface( fn=respond, type="messages", additional_inputs=[ gr.Textbox(value="You are a friendly assistant.", label="System message"), gr.Slider(1, 2048, 512, 1, label="Max new tokens"), gr.Slider(0.1, 4.0, 0.7, 0.1, label="Temperature"), gr.Slider(0.1, 1.0, 0.95, 0.05, label="Top-p"), ], title="🤖 Gyaanchand 3B (Hosted)", description="Inference powered by Hugging Face Hub.", ) if __name__ == "__main__": chatbot.launch(share=True, ssr_mode=False)