Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,10 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
4 |
import torch
|
5 |
|
6 |
title = """# 👋🏻Welcome To 🌟Tonic's🌐Aya-101"""
|
7 |
-
description = """
|
|
|
|
|
|
|
8 |
|
9 |
device = "cuda"
|
10 |
checkpoint = "CohereForAI/aya-101"
|
@@ -12,18 +15,10 @@ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
|
12 |
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map=device)
|
13 |
|
14 |
@spaces.GPU
|
15 |
-
def aya(text):
|
16 |
-
"""
|
17 |
-
Translates the input text to English using the Aya model.
|
18 |
-
Assumes the model can automatically detect the input language.
|
19 |
-
"""
|
20 |
model.to(device)
|
21 |
-
|
22 |
inputs = tokenizer.encode(text, return_tensors="pt").to(device)
|
23 |
-
|
24 |
-
outputs = model.generate(inputs, max_new_tokens=128)
|
25 |
-
|
26 |
-
|
27 |
translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
28 |
return translation
|
29 |
|
@@ -31,11 +26,11 @@ def main():
|
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown(title)
|
33 |
gr.Markdown(description)
|
|
|
|
|
|
|
34 |
output_text = gr.Textbox(label="🌐Aya", interactive=False)
|
35 |
-
|
36 |
-
input_text = gr.Textbox(label="🗣️Input Text")
|
37 |
-
submit_button = gr.Button("Translate") # Add a button to submit the input
|
38 |
-
submit_button.click(fn=aya, inputs=input_text, outputs=output_text)
|
39 |
|
40 |
demo.launch()
|
41 |
|
|
|
4 |
import torch
|
5 |
|
6 |
title = """# 👋🏻Welcome To 🌟Tonic's🌐Aya-101"""
|
7 |
+
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 !
|
8 |
+
You can also use 🌐Aya-101 by cloning this space. Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/Aya?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3> the easiest way to use Aya-101 is to use the Cohere CLI and their playground. Try finetuning the version with open weights !
|
9 |
+
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 🤗
|
10 |
+
"""
|
11 |
|
12 |
device = "cuda"
|
13 |
checkpoint = "CohereForAI/aya-101"
|
|
|
15 |
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map=device)
|
16 |
|
17 |
@spaces.GPU
|
18 |
+
def aya(text, max_new_tokens):
|
|
|
|
|
|
|
|
|
19 |
model.to(device)
|
|
|
20 |
inputs = tokenizer.encode(text, return_tensors="pt").to(device)
|
21 |
+
outputs = model.generate(inputs, max_new_tokens=max_new_tokens)
|
|
|
|
|
|
|
22 |
translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
return translation
|
24 |
|
|
|
26 |
with gr.Blocks() as demo:
|
27 |
gr.Markdown(title)
|
28 |
gr.Markdown(description)
|
29 |
+
input_text = gr.Textbox(label="🗣️Input Text")
|
30 |
+
max_new_tokens_slider = gr.Slider(minimum=150, maximum=1648, step=1, value=250, label="Size of your inputs and answer")
|
31 |
+
submit_button = gr.Button("Use🌐Aya")
|
32 |
output_text = gr.Textbox(label="🌐Aya", interactive=False)
|
33 |
+
submit_button.click(fn=aya, inputs=[input_text, max_new_tokens_slider], outputs=output_text)
|
|
|
|
|
|
|
34 |
|
35 |
demo.launch()
|
36 |
|