import gradio as gr from transformers import pipeline """ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference """ model_name = "Joetib/en-twi-llama-3.2-1B" from transformers import pipeline p = pipeline("text-generation", model=model_name, device_map="auto") def respond( message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p, ): messages = [{"role": "system", "content": system_message}] message = f" {system_message} [INST] {message} [/INST]" final = "" for response in p(message, max_new_tokens=20, do_sample=True, temperature=1, ): text = response["generated_text"].split("[/INST]")[-1] final += text return final """ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface """ demo = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value="Translate to Twi", label="System message"), gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider( minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)", ), ], ) if __name__ == "__main__": demo.launch()