Spaces:
Runtime error
Runtime error
ShankarsanDas
commited on
Commit
•
c9237d5
1
Parent(s):
e993d88
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
6 |
+
from collections import Counter
|
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(lang))
|
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 |
+
How do you think life originated on
|
22 |
+
earth and what insights does that give us about life
|
23 |
+
if we go back to the origin of earth and
|
24 |
+
you think about maybe 4.7 4.6 4.5 billion years ago planet was quite hot
|
25 |
+
there was a limited number of minerals there was some carbon some water and i
|
26 |
+
think that maybe it's a really simple set of chemistry that we we really don't understand
|
27 |
+
so that means you've got a finite number of elements that are going to react very simply with one another
|
28 |
+
and out of that mess comes a cell so literally sand turns into cells and it seems to happen quick
|
29 |
+
so what i think i can say with some degree of i think not certainty but curiosity
|
30 |
+
genuine curiosity is that life happened fast yeah so when we say fast
|
31 |
+
this is a pretty surprising fact and maybe you can actually correct me and elaborate but it seems like most
|
32 |
+
like 70 or 80 percent of the time that earth has been around there's been life on it like some very significant
|
33 |
+
percentage so when you say fast like the slow part is from single cell
|
34 |
+
or from bacteria to some more complicated organism it seems like most of the time that earth has been around
|
35 |
+
it's been single cell or like very basic organisms like a couple billion years but yeah you're
|
36 |
+
right that that's really i recently kind of revisited our history and saw this
|
37 |
+
and i was just looking at the timeline wait a minute like how did life just spring
|
38 |
+
up so quickly like really quickly that makes me think that it really wanted to like
|
39 |
+
put another way it's very easy for life to spring yeah i agree i think it's much
|
40 |
+
more inevitable and i think um i try to kind of not provoke but try and push
|
41 |
+
chemists to think about because chemists are part are central to this problem right of understanding the origin of life on
|
42 |
+
earth at least because we're made of made of chemistry but i wonder if the origin of life
|
43 |
+
on a planet or so the emergence of life on the planet is as common as the formation of a star
|
44 |
+
and if you start framing it in that way it allows you to then look at the universe slightly differently because
|
45 |
+
um and we can get into this i think in quite some detail but i think i to to come back to your question i have
|
46 |
+
little idea of how life got started but i know it was simple and i know that the process of selection
|
47 |
+
had to occur before the biology was established so that selection
|
48 |
+
built the framework from which life kind of grew in complexity and
|
49 |
+
capability and functionality and autonomy and i think these are all really important words that we can
|
50 |
+
unpack over the next while can you say all the words again so he says selection
|
51 |
+
so natural selection eight the original a b testing and so and then complexity
|
52 |
+
and then or the degree of autonomy and sophistication because i think that people misunderstand what life is um
|
53 |
+
some people say that life is a cell and some people that say that life is a a virus or life is a you know an on off
|
54 |
+
switch i don't think it's that life is the universe developing a memory
|
55 |
+
and the laws of physics and the way well there are no laws of physics physics is just memory free stuff
|
56 |
+
right there's only a finite number of ways you can arrange the fundamental particles to
|
57 |
+
do the things life is the universe developing
|
58 |
+
a memory so it's like sewing a piece of art slowly
|
59 |
+
and then you can look back at it so
|
60 |
+
so there's a stickiness to life it's like universe doing stuff and when you say memory it's like
|
61 |
+
there's a stickiness to a bunch of the stuff that's building together yeah so like you can in a stable way like uh
|
62 |
+
trace back the complexity and that tells a coherent story yeah and
|
63 |
+
i think yeah okay that's by the way very poetic and beautiful
|
64 |
+
life is the universe developing a memory [Music] okay and then there's autonomy you said
|
65 |
+
complexity we'll talk about but it's a really interesting idea that selection preceded biology
|
66 |
+
yeah i think yes so what first of all what is chemistry like does sand still count as chemistry
|
67 |
+
sure i mean as a chemist they can't carry a chemist if i'm allowed a card i don't know i don't know what i am most
|
68 |
+
days what is the card made of what's the chemical composition of the card
|
69 |
+
yeah so um what is chemistry well chemistry is the thing that happens when you bring electrons together and you form bonds
|
70 |
+
so bonds well i say to people when they talk about life elsewhere and i just say well there's bonds
|
71 |
+
there's hope because bonds allow you to get heterogeneity they allow you to record those memories or at least on
|
72 |
+
earth um you could imagine uh you know a stannis left lemtrey world
|
73 |
+
where you might have life emerging or intelligence emerging before life that may be something to on like solaris or
|
74 |
+
something but you know to get to selection if you can form if atoms can
|
75 |
+
combine and form bonds those bonds uh those atoms can bond to different elements and those and those
|
76 |
+
molecules will have different identities and interact with each other differently and then you can start to have some degree
|
77 |
+
of causation or interaction and then selection and then put and then existence
|
78 |
+
and then you you you go you go up the kind of the path of complexity and so at
|
79 |
+
least on earth as we know it there are there is a sufficient pool of available chemicals to start create
|
80 |
+
searching that combinatorial space of bonds so okay this is a really interesting
|
81 |
+
question let's let's lay it out so bonds almost like cards we say there's bonds
|
82 |
+
there is uh life there's intelligence there's consciousness and what you just made me
|
83 |
+
realize is um
|
84 |
+
those can emerge or let's put bonds aside uh those can emerge in any order
|
85 |
+
that's that's really brilliant so intelligence can come before life it's
|
86 |
+
like pan psychists believe that consciousness com i guess comes before
|
87 |
+
life and before intelligence so consciousness like permeates all matter it's some kind of fabric of
|
88 |
+
reality okay so like within this framework you can kind of arrange everything but you need to have the
|
89 |
+
bonds um that's precedes everything else oh and the other thing is selection
|
90 |
+
so like the mechanism of selection that could uh proceed see couldn't that proceed
|
91 |
+
bonds to whatever the house election so i would say that there is an elegant order to it that bonds
|
92 |
+
allow selection allows the emergence of life allows the emergence of multicellularity and then
|
93 |
+
more information processing building state machines all the way up however you could imagine a situation if you had
|
94 |
+
um i don't know a neutron star or a sun or a ferromagnetic loops interacting with one another
|
95 |
+
and these oscillators building state machines and these state machines reading something out in the environment
|
96 |
+
over time these state machines would be able to literally record what happened in the past and sense what's going on in the
|
97 |
+
present and imagine the future however i don't think it's ever going to be with
|
98 |
+
within a human comprehension that type of life um i wouldn't count it out because um
|
99 |
+
you know whenever you i know in science whenever i say something's impossible i then wake up the next day and say no that's actually wrong i mean there are
|
100 |
+
there are some limits of course um i don't see myself traveling fast and light any time soon but eric weinstein
|
101 |
+
says that's possible so he will say europe sure but i'm an experimentalist as well so one of my i have two super
|
102 |
+
powers and my stupidity and i don't mean that is a you know i'm like absolutely completely
|
103 |
+
witless but i mean my ability to kind of just start again and ask the question and then do it with an experiment i
|
104 |
+
always wanted to be a theoretician growing up but i just didn't have the just didn't have the intellectual capability but i i was able to think of
|
105 |
+
experiments in my head i could then do in my lab or in that you know when i was a with a child
|
106 |
+
outside and then those experiments in my head and then outside reinforce one another so i think that's a very good
|
107 |
+
way of kind of grounding the science right well that's the nice way to think about theoreticians is they're just
|
108 |
+
people who run experiments in their head i mean that's exactly what einstein did right and but you were also capable of
|
109 |
+
doing that in the head in your head inside your head and in the real world and the connection between the two
|
110 |
+
is when you first discovered your superpower stupidity i like it okay what's your second superpower oh your accent or
|
111 |
+
it's that well i don't know i'm my i like i am genuinely curious so my curious so i have a you know like
|
112 |
+
everybody ego problems but my curiosity is bigger than my ego so as long as that happens i i can i can that's awesome
|
113 |
+
that is so powerful you're just dropping some powerful lines so curiosity is bigger than ego that's something i
|
114 |
+
have to think about because you always struggle about the role of ego in life and um
|
115 |
+
that's that's so nice to think about don't think about the size of ego the absolute size of ego think about the
|
116 |
+
relative size of ego to the other the other horses pulling at you and if the
|
117 |
+
curiosity one is bigger then uh ego will do just fine and make you uh fun to talk
|
118 |
+
to anyway so those are the two superpowers how do those connect to natural selection or in selection and
|
119 |
+
bonds and i forgot already life and consciousness so that we're going back to selection in
|
120 |
+
the universe and origin of life on earth i mean um selection has a for i'm
|
121 |
+
convinced that selection is a force in the universe not me not a fundamental force but a but a directing but it is a
|
122 |
+
directing force because existence although um existence appears to be the default
|
123 |
+
um the existence of what why does um we can get to this later i think but
|
124 |
+
it's amazing that the discreet things exist and you know you see this cup it's not
|
125 |
+
the you know sexiest cup in the world but it's pretty functional this cup um
|
126 |
+
the complexity of this cup isn't just in the object it is literally the lineage of people making cups and recognizing
|
127 |
+
that seeing that in their head making an abstraction of a cup and then making a different one so
|
128 |
+
i wonder how many billions of cups have you know come before this one and
|
129 |
+
that's the process of selection and existence and the only reason the cup is still used is quite useful i like the handle you know it's convenient so i
|
130 |
+
don't die i keep hydration um and so i think we are missing something fundamental in the universe about
|
131 |
+
selection and i think what biology is is a is a selection amplifier
|
132 |
+
and that the this is where autonomy comes in and actually i think that how humanity is going to humans and
|
133 |
+
and autonomous robots or whatever we're going to call them in the future we'll we'll supercharge that even further so
|
134 |
+
selection is happening in the universe but if you look in the asteroid belt selection if objects are being kicked in
|
135 |
+
and out the asteroid belt um those trajectories are quite complex you don't really look at that as productive
|
136 |
+
selection because it's not doing anything to improve its function but is it the asteroid belt has existed for some time
|
137 |
+
"""
|
138 |
+
|
139 |
+
iface = gr.Interface(create_wc,
|
140 |
+
["text", gr.inputs.Dropdown(["en", "es"]) ,"text", "image", "text"],
|
141 |
+
"pil",
|
142 |
+
examples = [[text_example, "en", "um, i, i'm, we're, like, really, no, say, yeah, just, think, can", "roundrectangle.png", "128,0,0"]],
|
143 |
+
title="Visual Cluster Word Cloud Builder",
|
144 |
+
description="Create a word cluster visualization from a body or corpus of text. Word frequency makes the word size larger, and the image supplied can act as a mask to shape the visualization how you like. The custom stop word field allows you to enter a comma separated list of words you would like to exclude from the visualization.")
|
145 |
+
|
146 |
+
iface.launch()
|