A-Duss commited on
Commit
635f231
1 Parent(s): c978338

First working version

Browse files
app.py CHANGED
@@ -1,39 +1,81 @@
1
  import gradio as gr
2
  from shitsu import ShitsuScorer
3
 
 
4
 
5
- text_list = [
6
- "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.",
7
- "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."]
8
 
9
- # 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'
10
- language_code = "en"
11
- scorer = ShitsuScorer(language_code)
12
- scores = scorer.score(text_list)
13
- print(scores)
14
- # array([ 0.9897383 , -0.08109612], dtype=float32)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- def get_score(user_text, language_code):
17
- scorer = ShitsuScorer(language_code)
18
- scores = scorer.score(user_text)
19
- return scores[0]
20
 
21
- 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']
22
 
23
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
24
  with gr.Row():
25
  user_text = gr.Textbox(label='Input text...')
26
- submit_btn = gr.Button("Submit", scale=0)
 
 
 
 
 
27
  # Searchable dropdown to choose language
28
- language_choice = gr.Dropdown(
29
- choices=language_options,
30
- label="Choose a language",
31
- info="Type to search",
32
- allow_custom_value=True, # Allows typing to search
33
- )
34
- score = gr.Number(label="Result")
35
 
36
- user_text.submit(get_score, inputs=[user_text, language_choice], outputs=[score])
37
- submit_btn.click(get_score, inputs=[user_text, language_choice], outputs=[score])
 
 
 
 
 
 
 
 
 
38
 
39
  demo.launch()
 
1
  import gradio as gr
2
  from shitsu import ShitsuScorer
3
 
4
+ scorer = ShitsuScorer('en')
5
 
6
+ def get_score(user_text):
7
+ score = scorer.score([user_text])[0]
8
+ yield f'<div class="nice-box"> Score: {score}</div>'
9
 
10
+ #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']
11
+ #https://huggingface.co/spaces/Dusduo/shitsu-text-scorer-demo/shitsu-logo.jpeg
12
+ css = '''
13
+ #gen_btn{height: 100%}
14
+ #title{text-align: center}
15
+ #title h1{font-size: 3em; display:inline-flex; align-items:center}
16
+ #title img{width: 100px; margin-right: 0.5em}
17
+ #gallery .grid-wrap{height: 10vh}
18
+ #lora_list{background: var(--block-background-fill);padding: 0 1em .3em; font-size: 90%}
19
+ .card_internal{display: flex;height: 100px;margin-top: .5em}
20
+ .card_internal img{margin-right: 1em}
21
+ .styler{--form-gap-width: 0px !important}
22
+ .nice-box {
23
+ border: 2px solid #007bff;
24
+ border-radius: 10px;
25
+ padding: 15px;
26
+ background-color: #f8f9fa;
27
+ font-size: 18px;
28
+ text-align: center;
29
+ min-height: 60px;
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ }
34
+ '''
35
+ theme = gr.themes.Soft(
36
+ primary_hue="blue",
37
+ secondary_hue="sky",
38
+ )
39
 
 
 
 
 
40
 
41
+ with gr.Blocks(theme=theme, css=css) as demo:
42
 
43
+ title = gr.HTML(
44
+ """<h1><img src="https://huggingface.co/spaces/Dusduo/shitsu-text-scorer-demo/shitsu-logo.jpeg" alt="LightBlue"> Shitsu Text Scorer</h1>""",
45
+ elem_id="title",
46
+ )
47
+ gr.Markdown(
48
+ """This is a demo of [Shitsu text scorer](https://huggingface.co/lightblue/shitsu_text_scorer) which scores text based on the amount of useful, textbook-like information in it.
49
+
50
+ It outputs a score generally between 0 and 1 but can exceed both of these bounds as it is a regressor.
51
+ """
52
+ )
53
  with gr.Row():
54
  user_text = gr.Textbox(label='Input text...')
55
+ with gr.Column(scale=0):
56
+ submit_btn = gr.Button("Submit")
57
+ score = gr.HTML(
58
+ value='<div class="nice-box"> Score... </div>',
59
+ label="Output"
60
+ )
61
  # Searchable dropdown to choose language
62
+ # language_choice = gr.Dropdown(
63
+ # choices=language_options,
64
+ # label="Choose a language",
65
+ # info="Type to search",
66
+ # allow_custom_value=True, # Allows typing to search
67
+ # )
 
68
 
69
+ gr.Markdown(
70
+ """
71
+ This model is based on fasttext embeddings, meaning that it can be used on large amounts of data with limited compute quickly.
72
+
73
+ This scorer can be used to filter useful information from large text corpora in many languages.
74
+
75
+ This model can also be found on [Github](https://github.com/lightblue-tech/shitsu) and has its own pip installable package.
76
+ """
77
+ )
78
+ user_text.submit(get_score, inputs=[user_text], outputs=[score])
79
+ submit_btn.click(get_score, inputs=[user_text], outputs=[score])
80
 
81
  demo.launch()
lightblue-rectangular-logo.png ADDED
lightblue-squared-logo.jpeg ADDED
shitsu-logo.jpeg ADDED