File size: 994 Bytes
b333520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr

with gr.Blocks() as demo:
    textbox = gr.Textbox(value=['Connected Trip', 'Booking.com', 'Trip Planner'])
    textbox_2 = gr.Textbox()
    button = gr.Button()

    @button.click(inputs=[textbox], outputs=[textbox_2])
    def fn_1(textbox):
        def is_i18n_data(value):
            return isinstance(value, dict) and 'text' in value and 'locale' in value
    
        if is_i18n_data(textbox):
            text = textbox['text']
        else:
            text = str(textbox)
    
        char_count = {}
        for char in text:
            if char in char_count:
                char_count[char] += 1
            else:
                char_count[char] = 1
    
        sorted_char_count = sorted(char_count.items(), key=lambda item: item[1], reverse=True)
    
        report = "Character Count Report:\n"
        for char, count in sorted_char_count:
            report += f"Character: '{char}' - Count: {count}\n"
    
        return report.strip()

demo.launch()