File size: 5,304 Bytes
f59c7b5
c978338
f59c7b5
635f231
f59c7b5
88abc31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635f231
 
 
c978338
635f231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c978338
88abc31
635f231
c978338
635f231
88abc31
635f231
 
 
88abc31
635f231
 
 
 
c978338
88abc31
635f231
 
 
 
 
 
88abc31
 
 
 
c978338
635f231
 
 
 
 
 
c978338
635f231
 
 
 
 
 
 
 
 
88abc31
 
635f231
 
c978338
f59c7b5
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import gradio as gr
from shitsu import ShitsuScorer

scorer = ShitsuScorer('en')

example_inputs = [
    "Photosynthesis is the process by which green plants and some other organisms use sunlight to synthesize foods with the help of chlorophyll. It involves the intake of carbon dioxide and water and produces glucose and oxygen as by-products.",
    "Hey, how was your day? Did you manage to finish that project you were working on?",
    "In economics, the law of supply and demand describes the relationship between the availability of a particular product and the desire for that product. When supply increases, prices tend to drop, and when demand increases, prices tend to rise.",
    "The Pythagorean theorem is a fundamental relation in Euclidean geometry among the three sides of a right triangle. It states that the square of the hypotenuse is equal to the sum of the squares of the other two sides.",
    "Hey, do you want to grab coffee later? There's a new café that opened downtown.",
    "Newton's second law of motion states that the acceleration of an object is directly proportional to the net force acting on the object and inversely proportional to the object's mass. The formula for this is F = ma.",
    "The Beatles were a popular band in the 1960s. They released many hit songs.",
    "In computer science, an algorithm is a finite sequence of well-defined instructions, typically used to solve a class of problems or perform a computation. Algorithms are essential to the functioning of modern software systems.",
    "Chocolate is a type of sweet food that people often eat for dessert.",
    "I'm thinking of going to the beach this weekend. The weather is supposed to be great!",
    "Quantum mechanics is a fundamental theory in physics that provides a description of the physical properties of nature at the scale of atoms and subatomic particles.",
    "I saw a great movie last night. You should check it out if you get a chance.",
    "The mitochondrion is known as the powerhouse of the cell because it generates most of the cell's supply of adenosine triphosphate (ATP), used as a source of chemical energy.",
    "Can you believe it's already September? This year is flying by!"
]

def get_score(user_text):
    score = scorer.score([user_text])[0]
    yield f'<div class="nice-box"> Score: {score}</div>'

#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']
#https://huggingface.co/spaces/Dusduo/shitsu-text-scorer-demo/shitsu-logo.jpeg
css = '''
#gen_btn{height: 100%}
#title{text-align: center}
#title h1{font-size: 3em; display:inline-flex; align-items:center}
#title img{width: 100px; margin-right: 0.5em}
#gallery .grid-wrap{height: 10vh}
#lora_list{background: var(--block-background-fill);padding: 0 1em .3em; font-size: 90%}
.card_internal{display: flex;height: 100px;margin-top: .5em}
.card_internal img{margin-right: 1em}
.styler{--form-gap-width: 0px !important}
.nice-box {
    border: 2px solid #007bff;
    border-radius: 10px;
    padding: 15px;
    background-color: #f8f9fa;
    font-size: 18px;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
'''
theme = gr.themes.Soft(
    primary_hue="blue",
    secondary_hue="sky",
)

#"https://huggingface.co/spaces/Dusduo/shitsu-text-scorer-demo/shitsu-logo.jpeg"
with gr.Blocks(theme=theme, css=css) as demo:

    title = gr.HTML(
        """<h1><img src="file=shitsu-logo.jpeg" alt="LightBlue"> Shitsu Text Scorer</h1>""",
        elem_id="title",
    )
    gr.Markdown(
    """This is a demo of [Shitsu text scorer](https://huggingface.co/lightblue/shitsu_text_scorer) for English, which scores text based on the amount of useful, textbook-like information in it.
    
    It outputs a score generally between 0 and 1 but can exceed both of these bounds as it is a regressor.
    """
    )
    with gr.Row():
        user_text = gr.Textbox(label='Input text', placeholder='Type something here...')
        with gr.Column(scale=0):
            submit_btn = gr.Button("Submit")
            score = gr.HTML(
                value='<div class="nice-box"> Score...  </div>',
                label="Output"
            )
    
    # Add examples to the textbox
    gr.Examples(examples=example_inputs, inputs=user_text)
    
    # 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
    # )
    
    gr.Markdown(
    """
    This model is based on fasttext embeddings, meaning that it can be used on large amounts of data with limited compute quickly.

    This scorer can be used to filter useful information from large text corpora in many languages.  
    
    This model can also be found on [Github](https://github.com/lightblue-tech/shitsu) and has its own pip installable package. 
    """
    )
    
    # Set up the user submit events
    user_text.submit(get_score, inputs=[user_text], outputs=[score])
    submit_btn.click(get_score, inputs=[user_text], outputs=[score])
    
demo.launch()