subhannadeem1 commited on
Commit
2ac28f4
·
1 Parent(s): f8a8bb5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import spacy
4
+ nlp = spacy.load('en_core_web_sm')
5
+
6
+
7
+ def count_verbs(doc):
8
+ verbs = 0
9
+ for token in doc:
10
+ if token.pos_ == "VERB":
11
+ verbs += 1
12
+ return verbs
13
+
14
+ def greet(sent):
15
+ doc = nlp(sent)
16
+ nouns = 0
17
+ for token in doc:
18
+ if token.pos_ == "NOUN":
19
+ nouns += 1
20
+ verbs = count_verbs(doc)
21
+ length = len(sent.split())
22
+ return (f"Your sentence has {length} word(s).\n Your sentence has {nouns} noun(s).\n Your sentence has {verbs} verb(s).")
23
+
24
+
25
+
26
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text", examples = [
27
+ ["The Moon's orbit around Earth takes a long time."],
28
+ ["The smooth Borealis basin in the Northern Hemisphere covers 40%."]])
29
+ iface.launch(debug=True)