Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
return "Hello " + name + "!!, Your name has {length} letters in it."
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|