import spaces import gradio as gr from transformers import AutoModelForSeq2SeqLM, AutoTokenizer import torch title = """# 👋🏻Welcome To 🌟Tonic's🌐Aya-101""" description = """The Aya model is a massively multilingual generative language model that follows instructions in 101 languages. You can build with this endpoint using🌐Aya-101 available here : [CohereForAI/aya-101](https://huggingface.co/CohereForAI/aya-101). Try your own language out ! You can also use 🌐Aya-101 by cloning this space. Simply click here: Duplicate Space the easiest way to use Aya-101 is to use the Cohere CLI and their playground. Try finetuning the version with open weights ! Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻 [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) Math with [introspector](https://huggingface.co/introspector) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [MultiTonic](https://github.com/Tonic-AI/MultiToniic)🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗 """ device = "cuda" checkpoint = "CohereForAI/aya-101" tokenizer = AutoTokenizer.from_pretrained(checkpoint) model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map=device) @spaces.GPU def aya(text, max_new_tokens, repetition_penalty): model.to(device) inputs = tokenizer.encode(text, return_tensors="pt").to(device) outputs = model.generate(inputs, max_new_tokens=max_new_tokens, repetition_penalty=repetition_penalty) translation = tokenizer.decode(outputs[0], skip_special_tokens=True) return translation def main(): with gr.Blocks() as demo: gr.Markdown(title) gr.Markdown(description) input_text = gr.Textbox(label="🗣️Input Text") max_new_tokens_slider = gr.Slider(minimum=150, maximum=1648, step=1, value=250, label="Size of your inputs and answer") repetition_penalty_slider = gr.Slider(minimum=1.0, maximum=4.0, step=0.1, value=1.8, label="Repetition Penalty") submit_button = gr.Button("Use🌐Aya") output_text = gr.Textbox(label="🌐Aya", interactive=False) submit_button.click(fn=aya, inputs=[input_text, max_new_tokens_slider, repetition_penalty_slider], outputs=output_text) demo.launch() if __name__ == "__main__": main()