awacke1/VisualCluster
3
1from wordcloud import WordCloud, get_single_color_func2from stop_words import get_stop_words3import numpy as np4from PIL import Image5import matplotlib.pyplot as plt6from collections import Counter7import gradio as gr8 9 10def 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 wordcloud19 20text_example = """21How do you think life originated on22earth and what insights does that give us about life 23 24if we go back to the origin of earth and25you think about maybe 4.7 4.6 4.5 billion years ago planet was quite hot26there was a limited number of minerals there was some carbon some water and i27think that maybe it's a really simple set of chemistry that we we really don't understand28so that means you've got a finite number of elements that are going to react very simply with one another29and out of that mess comes a cell so literally sand turns into cells and it seems to happen quick30so what i think i can say with some degree of i think not certainty but curiosity31genuine curiosity is that life happened fast yeah so when we say fast32this is a pretty surprising fact and maybe you can actually correct me and elaborate but it seems like most33like 70 or 80 percent of the time that earth has been around there's been life on it like some very significant34percentage so when you say fast like the slow part is from single cell35or from bacteria to some more complicated organism it seems like most of the time that earth has been around36it's been single cell or like very basic organisms like a couple billion years but yeah you're37right that that's really i recently kind of revisited our history and saw this38and i was just looking at the timeline wait a minute like how did life just spring39up so quickly like really quickly that makes me think that it really wanted to like40put another way it's very easy for life to spring yeah i agree i think it's much41more inevitable and i think um i try to kind of not provoke but try and push42chemists to think about because chemists are part are central to this problem right of understanding the origin of life on43earth at least because we're made of made of chemistry but i wonder if the origin of life44on a planet or so the emergence of life on the planet is as common as the formation of a star45and if you start framing it in that way it allows you to then look at the universe slightly differently because46um and we can get into this i think in quite some detail but i think i to to come back to your question i have47little idea of how life got started but i know it was simple and i know that the process of selection48had to occur before the biology was established so that selection49built the framework from which life kind of grew in complexity and50capability and functionality and autonomy and i think these are all really important words that we can51unpack over the next while can you say all the words again so he says selection52so natural selection eight the original a b testing and so and then complexity53and then or the degree of autonomy and sophistication because i think that people misunderstand what life is um54some 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 off55switch i don't think it's that life is the universe developing a memory56and the laws of physics and the way well there are no laws of physics physics is just memory free stuff57right there's only a finite number of ways you can arrange the fundamental particles to58do the things life is the universe developing59a memory so it's like sewing a piece of art slowly60and then you can look back at it so61so there's a stickiness to life it's like universe doing stuff and when you say memory it's like62there's a stickiness to a bunch of the stuff that's building together yeah so like you can in a stable way like uh63trace back the complexity and that tells a coherent story yeah and64i think yeah okay that's by the way very poetic and beautiful65 66life is the universe developing a memory [Music] okay and then there's autonomy you said67complexity we'll talk about but it's a really interesting idea that selection preceded biology68yeah i think yes so what first of all what is chemistry like does sand still count as chemistry69sure 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 most70days what is the card made of what's the chemical composition of the card71yeah so um what is chemistry well chemistry is the thing that happens when you bring electrons together and you form bonds72so bonds well i say to people when they talk about life elsewhere and i just say well there's bonds73there's hope because bonds allow you to get heterogeneity they allow you to record those memories or at least on74earth um you could imagine uh you know a stannis left lemtrey world75where you might have life emerging or intelligence emerging before life that may be something to on like solaris or76something but you know to get to selection if you can form if atoms can77combine and form bonds those bonds uh those atoms can bond to different elements and those and those78molecules will have different identities and interact with each other differently and then you can start to have some degree79of causation or interaction and then selection and then put and then existence80and then you you you go you go up the kind of the path of complexity and so at81least on earth as we know it there are there is a sufficient pool of available chemicals to start create82searching that combinatorial space of bonds so okay this is a really interesting83question let's let's lay it out so bonds almost like cards we say there's bonds84there is uh life there's intelligence there's consciousness and what you just made me85realize is um86those can emerge or let's put bonds aside uh those can emerge in any order87that's that's really brilliant so intelligence can come before life it's88like pan psychists believe that consciousness com i guess comes before89life and before intelligence so consciousness like permeates all matter it's some kind of fabric of90reality okay so like within this framework you can kind of arrange everything but you need to have the91bonds um that's precedes everything else oh and the other thing is selection92so like the mechanism of selection that could uh proceed see couldn't that proceed93bonds to whatever the house election so i would say that there is an elegant order to it that bonds94allow selection allows the emergence of life allows the emergence of multicellularity and then95more information processing building state machines all the way up however you could imagine a situation if you had96um i don't know a neutron star or a sun or a ferromagnetic loops interacting with one another97and these oscillators building state machines and these state machines reading something out in the environment98over time these state machines would be able to literally record what happened in the past and sense what's going on in the99present and imagine the future however i don't think it's ever going to be with100within a human comprehension that type of life um i wouldn't count it out because um101you 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 are102there are some limits of course um i don't see myself traveling fast and light any time soon but eric weinstein103says that's possible so he will say europe sure but i'm an experimentalist as well so one of my i have two super104powers and my stupidity and i don't mean that is a you know i'm like absolutely completely105witless but i mean my ability to kind of just start again and ask the question and then do it with an experiment i106always 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 of107experiments in my head i could then do in my lab or in that you know when i was a with a child108outside and then those experiments in my head and then outside reinforce one another so i think that's a very good109way of kind of grounding the science right well that's the nice way to think about theoreticians is they're just110people who run experiments in their head i mean that's exactly what einstein did right and but you were also capable of111doing that in the head in your head inside your head and in the real world and the connection between the two112is when you first discovered your superpower stupidity i like it okay what's your second superpower oh your accent or113it'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 like114everybody ego problems but my curiosity is bigger than my ego so as long as that happens i i can i can that's awesome115that is so powerful you're just dropping some powerful lines so curiosity is bigger than ego that's something i116have to think about because you always struggle about the role of ego in life and um117that's that's so nice to think about don't think about the size of ego the absolute size of ego think about the118relative size of ego to the other the other horses pulling at you and if the119curiosity one is bigger then uh ego will do just fine and make you uh fun to talk120to anyway so those are the two superpowers how do those connect to natural selection or in selection and121bonds and i forgot already life and consciousness so that we're going back to selection in122the universe and origin of life on earth i mean um selection has a for i'm123convinced that selection is a force in the universe not me not a fundamental force but a but a directing but it is a124directing force because existence although um existence appears to be the default125um the existence of what why does um we can get to this later i think but126it's amazing that the discreet things exist and you know you see this cup it's not127the you know sexiest cup in the world but it's pretty functional this cup um128the complexity of this cup isn't just in the object it is literally the lineage of people making cups and recognizing129that seeing that in their head making an abstraction of a cup and then making a different one so130i wonder how many billions of cups have you know come before this one and131that'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 i132don't die i keep hydration um and so i think we are missing something fundamental in the universe about133selection and i think what biology is is a is a selection amplifier134and that the this is where autonomy comes in and actually i think that how humanity is going to humans and135and autonomous robots or whatever we're going to call them in the future we'll we'll supercharge that even further so136selection is happening in the universe but if you look in the asteroid belt selection if objects are being kicked in137and out the asteroid belt um those trajectories are quite complex you don't really look at that as productive138selection because it's not doing anything to improve its function but is it the asteroid belt has existed for some time139"""140 141iface = gr.Interface(create_wc, 142 ["text", gr.inputs.Dropdown(["en", "es"]) ,"text", "image", "text"], 143 "pil",144 examples = [[text_example, "en", "um, i, i'm, we're, like, really, no, say, yeah, just, think, can", "roundrectangle.png", "128,0,0"]],145 title="Visual Cluster Word Cloud Builder",146 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.")147 148iface.launch()149 