Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,28 +46,30 @@ def unique_word_count(text="", state=None):
|
|
46 |
sorted_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)
|
47 |
return sorted_word_counts,
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Translate from English to French
|
58 |
|
59 |
langdest = gr.Dropdown(choices=["af", "de", "es", "ko", "ja", "zh-cn"], label="Choose Language", value="de")
|
60 |
|
61 |
-
"""
|
62 |
-
def VarTrans(text, langdest):
|
63 |
-
translated = translator.translate(text, dest=langdest)
|
64 |
-
SCtranslated = translator.translate(sentencechunks, dest=langdest)
|
65 |
-
RCtranslated = translator.translate(reversed_chunks, dest=langdest)
|
66 |
-
TWCtranslated = translator.translate(TWchunks, dest=langdest)
|
67 |
-
return translated, SCtranslated, RCtranslated, TWCtranslated
|
68 |
-
"""
|
69 |
-
|
70 |
-
ChunkModeDrop = gr.Dropdown(choices=["Chunks", "Reverse", "Three Word Chunks"], label="Choose Chunk Type")
|
71 |
|
72 |
def FrontRevSentChunk (Chunkmode, Translate, Text, langdest):
|
73 |
FinalOutput = ""
|
@@ -78,6 +80,8 @@ def FrontRevSentChunk (Chunkmode, Translate, Text, langdest):
|
|
78 |
FinalOutput += ReverseSentenceChunker(Text)
|
79 |
if Chunkmode=="Three Word Chunks":
|
80 |
FinalOutput += three_words_chunk(Text)
|
|
|
|
|
81 |
|
82 |
if Translate:
|
83 |
TransFinalOutput = FinalOutput
|
@@ -85,35 +89,43 @@ def FrontRevSentChunk (Chunkmode, Translate, Text, langdest):
|
|
85 |
FinalOutput += "\n" + translated.text
|
86 |
return FinalOutput
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
print(RCtranslated.text)
|
94 |
-
print(TWchunks)
|
95 |
-
print(TWCtranslated.text)
|
96 |
-
print(nouns_verbs)
|
97 |
-
"""
|
98 |
-
|
99 |
-
def Wordchunker(word):
|
100 |
-
chunks = []
|
101 |
-
for i in range(len(word)):
|
102 |
-
chunks.append(word[:i+1])
|
103 |
-
return chunks
|
104 |
-
|
105 |
-
word = "please"
|
106 |
-
wordchunks = Wordchunker(word)
|
107 |
-
print("\n")
|
108 |
-
print(wordchunks)
|
109 |
|
110 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
with gr.Blocks() as lliface:
|
113 |
-
|
|
|
|
|
|
|
|
|
114 |
gr.Interface(fn=FrontRevSentChunk, inputs=[ChunkModeDrop, "checkbox", "text", langdest], outputs="text")
|
115 |
-
gr.Interface(fn=keep_nouns_verbs, inputs=["text"], outputs="text", title="Noun and Verbs only (Plus punctuation")
|
116 |
gr.HTML("Add a codepen pen page here")
|
117 |
gr.Interface(fn=unique_word_count, inputs="text", outputs="text", title="Wordcounter")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
lliface.launch()
|
|
|
46 |
sorted_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)
|
47 |
return sorted_word_counts,
|
48 |
|
49 |
+
def Wordchunker(word):
|
50 |
+
chunks = []
|
51 |
+
for i in range(len(word)):
|
52 |
+
chunks.append(word[:i+1])
|
53 |
+
return chunks
|
54 |
+
|
55 |
+
def BatchWordChunk(sentence):
|
56 |
+
words = sentence.split(" ")
|
57 |
+
FinalOutput = ""
|
58 |
+
Currentchunks = ""
|
59 |
+
ChunksasString = ""
|
60 |
+
for word in words:
|
61 |
+
ChunksasString = ""
|
62 |
+
Currentchunks = Wordchunker(word)
|
63 |
+
for chunk in Currentchunks:
|
64 |
+
ChunksasString += chunk + " "
|
65 |
+
FinalOutput += "\n" + ChunksasString
|
66 |
+
return FinalOutput
|
67 |
|
68 |
# Translate from English to French
|
69 |
|
70 |
langdest = gr.Dropdown(choices=["af", "de", "es", "ko", "ja", "zh-cn"], label="Choose Language", value="de")
|
71 |
|
72 |
+
ChunkModeDrop = gr.Dropdown(choices=["Chunks", "Reverse", "Three Word Chunks", "Spelling Chunks"], label="Choose Chunk Type", value="Chunks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
def FrontRevSentChunk (Chunkmode, Translate, Text, langdest):
|
75 |
FinalOutput = ""
|
|
|
80 |
FinalOutput += ReverseSentenceChunker(Text)
|
81 |
if Chunkmode=="Three Word Chunks":
|
82 |
FinalOutput += three_words_chunk(Text)
|
83 |
+
if Chunkmode=="Spelling Chunks":
|
84 |
+
FinalOutput += BatchWordChunk(Text)
|
85 |
|
86 |
if Translate:
|
87 |
TransFinalOutput = FinalOutput
|
|
|
89 |
FinalOutput += "\n" + translated.text
|
90 |
return FinalOutput
|
91 |
|
92 |
+
def SepHypandSynExpansion(text):
|
93 |
+
# Tokenize the text
|
94 |
+
tokens = nltk.word_tokenize(text)
|
95 |
+
NoHits = "Words to pay special attention to: "
|
96 |
+
FinalOutput = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
# Find synonyms and hypernyms of each word in the text
|
99 |
+
for token in tokens:
|
100 |
+
synonyms = []
|
101 |
+
hypernyms = []
|
102 |
+
for synset in wordnet.synsets(token):
|
103 |
+
synonyms += synset.lemma_names()
|
104 |
+
hypernyms += [hypernym.name() for hypernym in synset.hypernyms()]
|
105 |
+
if not synonyms and not hypernyms:
|
106 |
+
NoHits += f"{token} | "
|
107 |
+
else:
|
108 |
+
FinalOutput += "\n" f"{token}: hypernyms={hypernyms}, synonyms={synonyms}"
|
109 |
+
return NoHits, FinalOutput
|
110 |
|
111 |
with gr.Blocks() as lliface:
|
112 |
+
with gr.Tab("Welcome"):
|
113 |
+
gr.HTML("<h1> Spaces Test - Still Undercontruction </h1> <p> Knowledge is a Language </p> <> Arrows app json creator for easy knowledge graphing and spacy POS graph? </p> <p> https://huggingface.co/spaces/RASMUS/Whisper-youtube-crosslingual-subtitles<br>, https://huggingface.co/spaces/vumichien/whisper-speaker-diarization<br> Maybe duplicate these, private them and then load into spaces? --> Whisper space for youtube, Clip Interrogator, load here and all my random functions esp. text to HTML </p>")
|
114 |
+
with gr.Tab("Transcribe - RASMUS Whisper"):
|
115 |
+
gr.Interface.load("spaces/RASMUS/Whisper-youtube-crosslingual-subtitles", title="Subtitles")
|
116 |
+
with gr.Tab("Chunks"):
|
117 |
gr.Interface(fn=FrontRevSentChunk, inputs=[ChunkModeDrop, "checkbox", "text", langdest], outputs="text")
|
118 |
+
gr.Interface(fn=keep_nouns_verbs, inputs=["text"], outputs="text", title="Noun and Verbs only (Plus punctuation)")
|
119 |
gr.HTML("Add a codepen pen page here")
|
120 |
gr.Interface(fn=unique_word_count, inputs="text", outputs="text", title="Wordcounter")
|
121 |
+
with gr.Tab("Unique words, Hypernyms and synonyms"):
|
122 |
+
gr.Interface(fn=SepHypandSynExpansion, inputs="text", outputs=["text", "text"], title="Word suggestions")
|
123 |
+
with gr.Tab("Timing Practice"):
|
124 |
+
gr.HTML("""<p class="codepen" data-height="300" data-default-tab="result" data-slug-hash="GRXKQgj" data-preview="true" data-editable="true" data-user="kwabs22" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">
|
125 |
+
<span>See the Pen <a href="https://codepen.io/kwabs22/pen/GRXKQgj">
|
126 |
+
Memorisation Aid</a> by kwabs22 (<a href="https://codepen.io/kwabs22">@kwabs22</a>)
|
127 |
+
on <a href="https://codepen.io">CodePen</a>.</span>
|
128 |
+
</p>
|
129 |
+
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>""")
|
130 |
|
131 |
lliface.launch()
|