import gradio as gr from shitsu import ShitsuScorer text_list = [ "Photosynthesis is a system of biological processes by which photosynthetic organisms, such as most plants, algae, and cyanobacteria, convert light energy, typically from sunlight, into the chemical energy necessary to fuel their metabolism.", "Congratulations! You have all been selected to receive a free gift card worth $1000. Click on this link [Link] to claim your reward now. Limited time offer, so act fast! Don't miss out on this amazing opportunity."] # Choose a language from one of: 'am', 'ar', 'bg', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'gu', 'ha', 'hi', 'hu', 'id', 'it', 'ja', 'jv', 'kn', 'ko', 'lt', 'mr', 'nl', 'no', 'yo', 'zh' language_code = "en" scorer = ShitsuScorer(language_code) scores = scorer.score(text_list) print(scores) # array([ 0.9897383 , -0.08109612], dtype=float32) def get_score(user_text, language_code): scorer = ShitsuScorer(language_code) scores = scorer.score(user_text) return scores[0] language_options = ['am', 'ar', 'bg', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'gu', 'ha', 'hi', 'hu', 'id', 'it', 'ja', 'jv', 'kn', 'ko', 'lt', 'mr', 'nl', 'no', 'yo', 'zh'] with gr.Blocks() as demo: with gr.Row(): user_text = gr.Textbox(label='Input text...') submit_btn = gr.Button("Submit", scale=0) # Searchable dropdown to choose language language_choice = gr.Dropdown( choices=language_options, label="Choose a language", info="Type to search", allow_custom_value=True, # Allows typing to search ) score = gr.Number(label="Result") user_text.submit(get_score, inputs=[user_text, language_choice], outputs=[score]) submit_btn.click(get_score, inputs=[user_text, language_choice], outputs=[score]) demo.launch()