Spaces:
Sleeping
Sleeping
T.Masuda
commited on
Commit
·
7cbb6be
1
Parent(s):
75c1398
create app
Browse files- README.md +1 -1
- app.py +38 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🏢
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: blue
|
|
|
|
| 1 |
---
|
| 2 |
+
title: WordNet Demo
|
| 3 |
emoji: 🏢
|
| 4 |
colorFrom: gray
|
| 5 |
colorTo: blue
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import nltk
|
| 3 |
+
nltk.download('wordnet')
|
| 4 |
+
nltk.download('omw-1.4')
|
| 5 |
+
from nltk.corpus import wordnet
|
| 6 |
+
|
| 7 |
+
def process_text(language, text):
|
| 8 |
+
if text is None or text.strip() == '':
|
| 9 |
+
yield [None, None]
|
| 10 |
+
return
|
| 11 |
+
|
| 12 |
+
lang = 'jpn' if language == 'japanese' else 'eng'
|
| 13 |
+
synsets = wordnet.synsets(text, lang=lang)
|
| 14 |
+
definitions = []
|
| 15 |
+
synonyms = []
|
| 16 |
+
antonyms = []
|
| 17 |
+
|
| 18 |
+
for synset in synsets:
|
| 19 |
+
definition = synset.definition(lang=lang)
|
| 20 |
+
if type(definition) is str:
|
| 21 |
+
definitions.append(definition)
|
| 22 |
+
else:
|
| 23 |
+
definitions.extend(definition)
|
| 24 |
+
for l in synset.lemmas(lang=lang):
|
| 25 |
+
synonyms.append(l.name())
|
| 26 |
+
if l.antonyms():
|
| 27 |
+
antonyms.append(l.antonyms()[0].name())
|
| 28 |
+
yield ['\n'.join(set(definitions)), ', '.join(set(synonyms))]
|
| 29 |
+
|
| 30 |
+
app = gr.Interface(
|
| 31 |
+
title='WordNet Demo',
|
| 32 |
+
fn=process_text,
|
| 33 |
+
inputs=[gr.Radio(['english', 'japanese'], value='english', label='language'), gr.Textbox()],
|
| 34 |
+
outputs=[gr.Textbox(label='definitions'), gr.Textbox(label='synonyms')],
|
| 35 |
+
allow_flagging='never',
|
| 36 |
+
)
|
| 37 |
+
app.queue(concurrency_count=20)
|
| 38 |
+
app.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
nltk
|