Spaces:
Sleeping
Sleeping
A-Duss
commited on
Commit
•
635f231
1
Parent(s):
c978338
First working version
Browse files- app.py +67 -25
- lightblue-rectangular-logo.png +0 -0
- lightblue-squared-logo.jpeg +0 -0
- shitsu-logo.jpeg +0 -0
app.py
CHANGED
@@ -1,39 +1,81 @@
|
|
1 |
import gradio as gr
|
2 |
from shitsu import ShitsuScorer
|
3 |
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
with gr.Row():
|
25 |
user_text = gr.Textbox(label='Input text...')
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
# Searchable dropdown to choose language
|
28 |
-
language_choice = gr.Dropdown(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
)
|
34 |
-
score = gr.Number(label="Result")
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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