File size: 717 Bytes
2ac28f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)