File size: 708 Bytes
dcb09fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr

with gr.Blocks() as demo:
    textbox = gr.Textbox(value=['Booking.com', 'Uber', 'Maarkplaats'])
    textbox_2 = gr.Textbox()

    @gr.on([], inputs=[textbox], outputs=[textbox_2])
    def fn_1(textbox):
        from collections import Counter
        
        if isinstance(textbox, str):
            text = textbox
        elif hasattr(textbox, 'text') and callable(textbox.text):
            text = textbox.text()
        else:
            raise ValueError("Unsupported type for textbox")
        
        char_count = Counter(text)
        sorted_char_count = sorted(char_count.items(), key=lambda item: item[1], reverse=True)
        
        return sorted_char_count

demo.launch()