new functionalities
Browse files- app.py +11 -18
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
from wordcloud import WordCloud,
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
import matplotlib.pyplot as plt
|
@@ -6,37 +7,29 @@ from collections import Counter
|
|
6 |
import gradio as gr
|
7 |
|
8 |
|
9 |
-
def
|
10 |
-
|
11 |
-
return "rgb(0, 0, 0)"
|
12 |
-
|
13 |
-
|
14 |
-
plt.show()
|
15 |
-
|
16 |
-
|
17 |
-
def create_wc(text, custom_sw, input_img):
|
18 |
STOPWORDS.update(custom_sw.replace(" ", "").split(","))
|
19 |
-
print(STOPWORDS)
|
20 |
mask = np.array(input_img)
|
21 |
wordcloud = WordCloud(background_color="rgba(0, 0, 0, 0)", mode="RGBA",mask=mask, width=1000, height=1500, stopwords=STOPWORDS).generate(text.lower())
|
22 |
-
wordcloud.recolor(
|
|
|
|
|
23 |
return wordcloud
|
24 |
|
25 |
text_example = """
|
26 |
Harry Potter is a series of seven fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).
|
27 |
-
|
28 |
The series was originally published in English by Bloomsbury in the United Kingdom and Scholastic Press in the United States. All versions around the world are printed by Grafica Veneta in Italy.[1] A series of many genres, including fantasy, drama, coming of age, and the British school story (which includes elements of mystery, thriller, adventure, horror, and romance), the world of Harry Potter explores numerous themes and includes many cultural meanings and references.[2] According to Rowling, the main theme is death.[3] Other major themes in the series include prejudice, corruption, and madness.[4]
|
29 |
-
|
30 |
Since the release of the first novel, Harry Potter and the Philosopher's Stone, on 26 June 1997, the books have found immense popularity, positive reviews, and commercial success worldwide. They have attracted a wide adult audience as well as younger readers and are often considered cornerstones of modern young adult literature.[5] As of February 2018, the books have sold more than 500 million copies worldwide, making them the best-selling book series in history, and have been translated into eighty languages.[6] The last four books consecutively set records as the fastest-selling books in history, with the final instalment selling roughly 2.7 million copies in the United Kingdom and 8.3 million copies in the United States within twenty-four hours of its release.
|
31 |
-
|
32 |
The original seven books were adapted into an eight-part namesake film series by Warner Bros. Pictures. In 2016, the total value of the Harry Potter franchise was estimated at $25 billion,[7] making Harry Potter one of the highest-grossing media franchises of all time. Harry Potter and the Cursed Child is a play based on a story co-written by Rowling.
|
33 |
-
|
34 |
The success of the books and films has allowed the Harry Potter franchise to expand with numerous derivative works, a travelling exhibition that premiered in Chicago in 2009, a studio tour in London that opened in 2012, a digital platform on which J. K. Rowling updates the series with new information and insight, and a pentalogy of spin-off films premiering in November 2016 with Fantastic Beasts and Where to Find Them, among many other developments. Themed attractions, collectively known as The Wizarding World of Harry Potter, have been built at several Universal Parks & Resorts amusement parks around the world.
|
35 |
"""
|
36 |
|
37 |
iface = gr.Interface(create_wc,
|
38 |
-
["text", "text", "image"],
|
39 |
"pil",
|
40 |
-
examples = [[text_example, "harry, potter", "circle.jpg"]]
|
|
|
|
|
41 |
|
42 |
iface.launch()
|
|
|
1 |
+
from wordcloud import WordCloud, get_single_color_func
|
2 |
+
from stop_words import get_stop_words
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
import matplotlib.pyplot as plt
|
|
|
7 |
import gradio as gr
|
8 |
|
9 |
|
10 |
+
def create_wc(text, lang, custom_sw, input_img, color_rgb):
|
11 |
+
STOPWORDS = set(get_stop_words('en'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
STOPWORDS.update(custom_sw.replace(" ", "").split(","))
|
|
|
13 |
mask = np.array(input_img)
|
14 |
wordcloud = WordCloud(background_color="rgba(0, 0, 0, 0)", mode="RGBA",mask=mask, width=1000, height=1500, stopwords=STOPWORDS).generate(text.lower())
|
15 |
+
# wordcloud.recolor(colormap=colormap)
|
16 |
+
wordcloud.recolor(color_func=get_single_color_func(f'rgb({color_rgb})'))
|
17 |
+
|
18 |
return wordcloud
|
19 |
|
20 |
text_example = """
|
21 |
Harry Potter is a series of seven fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).
|
|
|
22 |
The series was originally published in English by Bloomsbury in the United Kingdom and Scholastic Press in the United States. All versions around the world are printed by Grafica Veneta in Italy.[1] A series of many genres, including fantasy, drama, coming of age, and the British school story (which includes elements of mystery, thriller, adventure, horror, and romance), the world of Harry Potter explores numerous themes and includes many cultural meanings and references.[2] According to Rowling, the main theme is death.[3] Other major themes in the series include prejudice, corruption, and madness.[4]
|
|
|
23 |
Since the release of the first novel, Harry Potter and the Philosopher's Stone, on 26 June 1997, the books have found immense popularity, positive reviews, and commercial success worldwide. They have attracted a wide adult audience as well as younger readers and are often considered cornerstones of modern young adult literature.[5] As of February 2018, the books have sold more than 500 million copies worldwide, making them the best-selling book series in history, and have been translated into eighty languages.[6] The last four books consecutively set records as the fastest-selling books in history, with the final instalment selling roughly 2.7 million copies in the United Kingdom and 8.3 million copies in the United States within twenty-four hours of its release.
|
|
|
24 |
The original seven books were adapted into an eight-part namesake film series by Warner Bros. Pictures. In 2016, the total value of the Harry Potter franchise was estimated at $25 billion,[7] making Harry Potter one of the highest-grossing media franchises of all time. Harry Potter and the Cursed Child is a play based on a story co-written by Rowling.
|
|
|
25 |
The success of the books and films has allowed the Harry Potter franchise to expand with numerous derivative works, a travelling exhibition that premiered in Chicago in 2009, a studio tour in London that opened in 2012, a digital platform on which J. K. Rowling updates the series with new information and insight, and a pentalogy of spin-off films premiering in November 2016 with Fantastic Beasts and Where to Find Them, among many other developments. Themed attractions, collectively known as The Wizarding World of Harry Potter, have been built at several Universal Parks & Resorts amusement parks around the world.
|
26 |
"""
|
27 |
|
28 |
iface = gr.Interface(create_wc,
|
29 |
+
["text", gr.inputs.Dropdown(["en", "es"]) ,"text", "image", "text"],
|
30 |
"pil",
|
31 |
+
examples = [[text_example, "en", "harry, potter", "circle.jpg", "0,255,0"]],
|
32 |
+
title="Wordcloud",
|
33 |
+
description="Create a wordcloud from a text. Use the custom sw field to input custom stopwords separated by comma")
|
34 |
|
35 |
iface.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
wordcloud
|
2 |
pillow
|
3 |
matplotlib
|
|
|
|
1 |
wordcloud
|
2 |
pillow
|
3 |
matplotlib
|
4 |
+
stop-words
|