Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert app if requirement not installed on server #23

Open
MarcSkovMadsen opened this issue Nov 7, 2022 · 0 comments
Open

Cannot convert app if requirement not installed on server #23

MarcSkovMadsen opened this issue Nov 7, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@MarcSkovMadsen
Copy link
Contributor

Description

I've seen that Sophias NLP app does not convert. After some investigation I can see that its because the textblob library is not installed.

There are three issues with this

  1. There is no real error message to sophia
  2. The conversion does not retry converting but without the preview
  3. She can share the app

image

Reproduction steps

Requirements

No response

Code

#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import panel as pn
import requests
import pandas as pd
from textblob import TextBlob
pn.extension()
pn.extension('tabulator')
import warnings
warnings.filterwarnings('ignore')


# In[ ]:


sample_text = """
Happiness is a very complicated thing. Happiness can be used both in emotional or mental state context and can vary largely from a feeling from contentment to very intense feeling of joy. It can also mean a life of satisfaction, good well-being and so many more. Happiness is a very difficult phenomenon to use words to describe as it is something that can be felt only. Happiness is very important if we want to lead a very good life. Sadly, happiness is absent from the lives of a lot of people nowadays. We all have our own very different concept of happiness. Some of us are of the opinion that we can get happiness through money, others believe they can only get true happiness in relationships, some even feel that happiness can only be gotten when they are excelling in their profession.
As we might probably know, happiness is nothing more than the state of one being content and happy. A lot of people in the past, present and some (even in the future will) have tried to define and explain what they think happiness really is. So far, the most reasonable one is the one that sees happiness as something that can only come from within a person and should not be sought for outside in the world.
Some very important points about happiness are discussed below:
1. Happiness can’t be bought with Money:
A lot of us try to find happiness where it is not. We associate and equate money with happiness. If at all there is happiness in money then all of the rich people we have around us would never feel sad. What we have come to see is that even the rich amongst us are the ones that suffer depression, relationship problems, stress, fear and even anxiousness. A lot of celebrities and successful people have committed suicide, this goes a long way to show that money or fame does not guarantee happiness. This does not mean that it is a bad thing to be rich and go after money. When you have money, you can afford many things that can make you and those around you very happy.
2. Happiness can only come from within:
There is a saying that explains that one can only get true happiness when one comes to the realisation that only one can make himself/herself happy. We can only find true happiness within ourselves and we can’t find it in other people. This saying and its meaning is always hammered on in different places but we still refuse to fully understand it and put it into good use. It is very important that we understand that happiness is nothing more than the state of a person’s mind. Happiness cannot come from all the physical things we see around us. Only we through our positive emotions that we can get through good thoughts have the ability to create true happiness.
Our emotions are created by our thoughts. Therefore, it is very important that we work on having only positive thoughts and this can be achieved when we see life in a positive light."""


# In[ ]:


# from nltk.corpus import stopwords
# stoplist = stopwords.words('english') + ['though']
stoplist = ['i',
 'me',
 'my',
 'myself',
 'we',
 'our',
 'ours',
 'ourselves',
 'you',
 "you're",
 "you've",
 "you'll",
 "you'd",
 'your',
 'yours',
 'yourself',
 'yourselves',
 'he',
 'him',
 'his',
 'himself',
 'she',
 "she's",
 'her',
 'hers',
 'herself',
 'it',
 "it's",
 'its',
 'itself',
 'they',
 'them',
 'their',
 'theirs',
 'themselves',
 'what',
 'which',
 'who',
 'whom',
 'this',
 'that',
 "that'll",
 'these',
 'those',
 'am',
 'is',
 'are',
 'was',
 'were',
 'be',
 'been',
 'being',
 'have',
 'has',
 'had',
 'having',
 'do',
 'does',
 'did',
 'doing',
 'a',
 'an',
 'the',
 'and',
 'but',
 'if',
 'or',
 'because',
 'as',
 'until',
 'while',
 'of',
 'at',
 'by',
 'for',
 'with',
 'about',
 'against',
 'between',
 'into',
 'through',
 'during',
 'before',
 'after',
 'above',
 'below',
 'to',
 'from',
 'up',
 'down',
 'in',
 'out',
 'on',
 'off',
 'over',
 'under',
 'again',
 'further',
 'then',
 'once',
 'here',
 'there',
 'when',
 'where',
 'why',
 'how',
 'all',
 'any',
 'both',
 'each',
 'few',
 'more',
 'most',
 'other',
 'some',
 'such',
 'no',
 'nor',
 'not',
 'only',
 'own',
 'same',
 'so',
 'than',
 'too',
 'very',
 's',
 't',
 'can',
 'will',
 'just',
 'don',
 "don't",
 'should',
 "should've",
 'now',
 'd',
 'll',
 'm',
 'o',
 're',
 've',
 'y',
 'ain',
 'aren',
 "aren't",
 'couldn',
 "couldn't",
 'didn',
 "didn't",
 'doesn',
 "doesn't",
 'hadn',
 "hadn't",
 'hasn',
 "hasn't",
 'haven',
 "haven't",
 'isn',
 "isn't",
 'ma',
 'mightn',
 "mightn't",
 'mustn',
 "mustn't",
 'needn',
 "needn't",
 'shan',
 "shan't",
 'shouldn',
 "shouldn't",
 'wasn',
 "wasn't",
 'weren',
 "weren't",
 'won',
 "won't",
 'wouldn',
 "wouldn't",
 'though']


# In[ ]:


def get_sentiment(text):
    return pn.pane.Markdown(f"""
    Polarity (range from -1 negative to 1 positive): {TextBlob(text).polarity} \n
    Subjectivity (range from 0 objective to 1 subjective): {TextBlob(text).subjectivity}
    """)


# In[ ]:


def get_ngram(text):
    from sklearn.feature_extraction.text import CountVectorizer
    c_vec = CountVectorizer(stop_words=stoplist, ngram_range=(2,3))
    # matrix of ngrams
    try:
        ngrams = c_vec.fit_transform([text])
    except ValueError: # if less than 2 words, return empty result
        return pn.widgets.Tabulator(width=600)
    # count frequency of ngrams
    count_values = ngrams.toarray().sum(axis=0)
    # list of ngrams
    vocab = c_vec.vocabulary_
    df_ngram = pd.DataFrame(sorted([(count_values[i],k) for k,i in vocab.items()], reverse=True)
                ).rename(columns={0: 'frequency', 1:'bigram/trigram'})
    df_ngram['polarity'] = df_ngram['bigram/trigram'].apply(lambda x: TextBlob(x).polarity)
    df_ngram['subjective'] = df_ngram['bigram/trigram'].apply(lambda x: TextBlob(x).subjectivity)
    return pn.widgets.Tabulator(df_ngram, width=600, height=300)


# In[ ]:


def get_ntopics(text, ntopics):
    from sklearn.feature_extraction.text import TfidfVectorizer
    from sklearn.decomposition import NMF
    from sklearn.pipeline import make_pipeline
    tfidf_vectorizer = TfidfVectorizer(stop_words=stoplist, ngram_range=(2,3))
    nmf = NMF(n_components=ntopics)
    pipe = make_pipeline(tfidf_vectorizer, nmf)
    try:
        pipe.fit([text])
    except ValueError: # if less than 2 words, return empty result
        return
    message = ""
    for topic_idx, topic in enumerate(nmf.components_):
        message += "####Topic #%d: " % topic_idx
        message += ", ".join([tfidf_vectorizer.get_feature_names()[i]
                             for i in topic.argsort()[:-3 - 1:-1]])
        message += "\n"
    return pn.pane.Markdown(message)


# In[ ]:


explanation = pn.pane.Markdown("""
This app provides a simple text analysis for a given input text or text file. \n
- Sentiment analysis uses [TextBlob](https://textblob.readthedocs.io/).
- N-gram analysis uses [scikit-learn](https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html) to see which words show up together.
- Topic modeling uses [scikit-learn](https://scikit-learn.org/stable/auto_examples/applications/plot_topics_extraction_with_nmf_lda.html) NMF model and we can change the number of topics we'd like to see in the result.
""")

def get_text_results(_):
    return pn.Column(
        explanation,
        pn.pane.Markdown("""
        ##Sentiment analysis:"""),
        get_sentiment(text_widget.value.replace("\n", "")),
        pn.pane.Markdown("##N-gram analysis (bigram/trigram):"),
        get_ngram(text_widget.value.replace("\n", "")),
        pn.pane.Markdown("##Topic modeling:"),
        get_ntopics(text_widget.value.replace("\n", ""), ntopics_widget.value)
    )


# In[ ]:


button = pn.widgets.Button(name="Click me to run!")


# In[ ]:


file_input_widget = pn.widgets.FileInput()
def update_text_widget(event):
    text_widget.value = event.new.decode("utf-8")
# when the value of file_input_widget changes, 
# run this function to update the text of the text widget
file_input_widget.param.watch(update_text_widget, "value");


# In[ ]:


text_widget = pn.widgets.TextAreaInput(value=sample_text, height=300, name='Add text')


# In[ ]:


ntopics_widget = pn.widgets.IntSlider(name='Number of topics', start=2, end=10, step=1, value=3)


# In[ ]:


interactive = pn.bind(get_text_results, button)


# Layout using Template
template = pn.template.FastListTemplate(
    title='Simple Text Analysis', 
    sidebar=[
        button,
        ntopics_widget, 
        text_widget, 
        "Upload a text file",
        file_input_widget
    ],
    main=[pn.panel(interactive, loading_indicator=True)],
    accent_base_color="#88d8b0",
    header_background="#88d8b0",
)
template.servable()

Logs

2022-11-07 16:59:46,874 404 GET /apps-dev/b9ce668b-28d2-4a85-9023-0bcfdd0246bb/app.html (::1) 0.58ms
ERROR:bokeh.application.application:Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7fd517d6dac0>: No module named 'textblob'
File 'app.py', line 10, in <module>:
from textblob import TextBlob Traceback (most recent call last):
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/bokeh/application/handlers/code_runner.py", line 231, in run
    exec(self._code, module.__dict__)
  File "/tmp/tmpd6ezv0wh/source/app.py", line 10, in <module>
    from textblob import TextBlob
ModuleNotFoundError: No module named 'textblob'
 
Failed to convert source/app.py to pyodide-worker target: The file source/app.py does not publish any Panel contents. Ensure you have marked items as servable or added models to the bokeh document manually.
convert project: Elapsed time: 4.1261 seconds
2022-11-07 16:59:57,985 Error
Traceback (most recent call last):
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/reactive.py", line 413, in _comm_event
    self._process_bokeh_event(doc, event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/reactive.py", line 350, in _process_bokeh_event
    self._process_event(event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/widgets/button.py", line 184, in _process_event
    self.clicks += 1
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 367, in _f
    instance_param.__set__(obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 369, in _f
    return f(self, obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/__init__.py", line 625, in __set__
    super(Dynamic,self).__set__(obj,val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 369, in _f
    return f(self, obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1248, in __set__
    obj.param._call_watcher(watcher, event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2039, in _call_watcher
    self_._execute_watcher(watcher, (event,))
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2021, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/param.py", line 502, in event
    self.object.param.trigger(p_name)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1989, in trigger
    self_.set_param(**dict(params, **triggers))
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1925, in set_param
    return self_.update(kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1898, in update
    self_._batch_call_watchers()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2059, in _batch_call_watchers
    self_._execute_watcher(watcher, events)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2021, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 669, in caller
    return function()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 407, in _depends
    return func(*args, **kw)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/components/build_project.py", line 31, in _convert
    self._state.build()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 695, in build
    self.site.development_storage[key] = self.project
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 412, in __setitem__
    value.build(base_target=self.base_target)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 251, in build
    self._build_to_tmpdir(base_target=base_target)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 238, in _build_to_tmpdir
    text = app_html.read_text(encoding="utf8")
  File "/opt/conda/lib/python3.9/pathlib.py", line 1266, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/opt/conda/lib/python3.9/pathlib.py", line 1252, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "/opt/conda/lib/python3.9/pathlib.py", line 1120, in _opener
    return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'build/app.html'
ERROR:bokeh.application.application:Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7fd517d6dac0>: No module named 'textblob'
File 'app.py', line 10, in <module>:
from textblob import TextBlob Traceback (most recent call last):
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/bokeh/application/handlers/code_runner.py", line 231, in run
    exec(self._code, module.__dict__)
  File "/tmp/tmpd6ezv0wh/source/app.py", line 10, in <module>
    from textblob import TextBlob
ModuleNotFoundError: No module named 'textblob'
 
Failed to convert source/app.py to pyodide-worker target: The file source/app.py does not publish any Panel contents. Ensure you have marked items as servable or added models to the bokeh document manually.
convert project: Elapsed time: 0.6701 seconds
2022-11-07 17:00:48,713 Error
Traceback (most recent call last):
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/reactive.py", line 413, in _comm_event
    self._process_bokeh_event(doc, event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/reactive.py", line 350, in _process_bokeh_event
    self._process_event(event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/widgets/button.py", line 184, in _process_event
    self.clicks += 1
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 367, in _f
    instance_param.__set__(obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 369, in _f
    return f(self, obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/__init__.py", line 625, in __set__
    super(Dynamic,self).__set__(obj,val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 369, in _f
    return f(self, obj, val)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1248, in __set__
    obj.param._call_watcher(watcher, event)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2039, in _call_watcher
    self_._execute_watcher(watcher, (event,))
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2021, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/panel/param.py", line 502, in event
    self.object.param.trigger(p_name)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1989, in trigger
    self_.set_param(**dict(params, **triggers))
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1925, in set_param
    return self_.update(kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 1898, in update
    self_._batch_call_watchers()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2059, in _batch_call_watchers
    self_._execute_watcher(watcher, events)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 2021, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 669, in caller
    return function()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/.venv/lib/python3.9/site-packages/param/parameterized.py", line 407, in _depends
    return func(*args, **kw)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/components/build_project.py", line 31, in _convert
    self._state.build()
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 695, in build
    self.site.development_storage[key] = self.project
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 412, in __setitem__
    value.build(base_target=self.base_target)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 251, in build
    self._build_to_tmpdir(base_target=base_target)
  File "/home/jovyan/repos/private/awesome-panel/panel-sharing/src/panel_sharing/models.py", line 238, in _build_to_tmpdir
    text = app_html.read_text(encoding="utf8")
  File "/opt/conda/lib/python3.9/pathlib.py", line 1266, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/opt/conda/lib/python3.9/pathlib.py", line 1252, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "/opt/conda/lib/python3.9/pathlib.py", line 1120, in _opener
    return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'build/app.html'

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant