import gradio as gr | |
import pandas as pd | |
def topn_tokens(sequence, n): | |
chars = list(sequence) | |
n_column = [n] * len(chars) # Create a column with the chosen integer repeated | |
df = pd.DataFrame({'Character': chars, 'N': n_column}) # Create the DataFrame | |
return df | |
demo = gr.Interface( | |
topn_tokens, | |
[ | |
"text", | |
gr.Dropdown([int(i) for i in range(1, 21)]), # Dropdown with numbers from 1 to 20 | |
], | |
"dataframe", | |
description="Choose a number between 1-20 to display n tokens", | |
) | |
if __name__ == "__main__": | |
demo.launch() | |