Spaces:
Sleeping
Sleeping
import gradio as gr | |
import spacy | |
nlp = spacy.load('en_core_web_sm') | |
def count_verbs(doc): | |
verbs = 0 | |
for token in doc: | |
if token.pos_ == "VERB": | |
verbs += 1 | |
return verbs | |
def greet(sent): | |
doc = nlp(sent) | |
nouns = 0 | |
for token in doc: | |
if token.pos_ == "NOUN": | |
nouns += 1 | |
verbs = count_verbs(doc) | |
length = len(sent.split()) | |
return (f"Your sentence has {length} word(s).\n Your sentence has {nouns} noun(s).\n Your sentence has {verbs} verb(s).") | |
iface = gr.Interface(fn=greet, inputs="text", outputs="text", examples = [ | |
["The Moon's orbit around Earth takes a long time."], | |
["The smooth Borealis basin in the Northern Hemisphere covers 40%."]]) | |
iface.launch(debug=True) |