Commit
•
522d644
1
Parent(s):
0b01c5c
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,30 @@
|
|
1 |
-
|
2 |
-
torch
|
3 |
-
spacy
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
|
|
|
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
import spacy
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Load the spaCy model for POS tagging
|
8 |
+
nlp = spacy.load("en_core_web_sm")
|
9 |
+
|
10 |
+
def identify_nouns_verbs(text):
|
11 |
+
# Process the text with spaCy
|
12 |
+
doc = nlp(text)
|
13 |
+
|
14 |
+
# Extract nouns and verbs
|
15 |
+
nouns = [token.text for token in doc if token.pos_ == "NOUN"]
|
16 |
+
verbs = [token.text for token in doc if token.pos_ == "VERB"]
|
17 |
+
|
18 |
+
return {"Nouns": nouns, "Verbs": verbs}
|
19 |
+
|
20 |
+
# Create the Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=identify_nouns_verbs,
|
23 |
+
inputs=gr.inputs.Textbox(lines=10, placeholder="Enter your text here..."),
|
24 |
+
outputs=gr.outputs.JSON(),
|
25 |
+
title="Noun and Verb Identifier",
|
26 |
+
description="Enter a document or text to identify the nouns and verbs."
|
27 |
+
)
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
iface.launch()
|