File size: 1,007 Bytes
063421d
 
 
 
 
 
9dfa832
 
063421d
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import solara

sentence = solara.reactive("Solara makes our team more productive.")
word_limit = solara.reactive(10)
@solara.component
def Page():
    solara.Markdown("#Solara Template")
    solara.Markdown("Remember to add the 'app_port: 7860' to the README.md file")
    # Calculate word_count within the component to ensure re-execution when reactive variables change.
    word_count = len(sentence.value.split())
    solara.SliderInt("Word limit", value=word_limit, min=2, max=20)
    solara.InputText(label="Your sentence", value=sentence, continuous_update=True)
    # Display messages based on the current word count and word limit.
    if word_count >= int(word_limit.value):
        solara.Error(f"With {word_count} words, you passed the word limit of {word_limit.value}.")
    elif word_count >= int(0.8 * word_limit.value):
        solara.Warning(f"With {word_count} words, you are close to the word limit of {word_limit.value}.")
    else:
        solara.Success("Great short writing!")

Page()