Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Flask-Login user_loader??

I have a fully functional webapp that runs just fine on localhost. When I try to publish it to azure, it fails and the traceback says 'Missing user\_loader or request\_loader. Refer to http://flask-login.readthedocs.io/#how-it-works for more info.'

Code below.. unless I'm missing something really obvious, I have a user\_loader decorator and everything should be working. Is there an import problem or something?? THANKS!!!

​

\_\_init\_\_.py:

`##`

`from flask_login import LoginManager`

`##`

`login_manager = LoginManager(app)`
`login_manager.init_app(app)`

`##`

​

auth.py:

`@login_manager.user_loader`
`def load_user(user_id):`
`try:`
`return User.query.get(user_id)`
`except:`
`return None`

​

routes.py:

`from .auth import *`

`from . import login_manager`

`##`

`@app.route('/login', methods = ['GET','POST'])`
`def login():`
`if current_user.is_authenticated:`
`return redirect(url_for('historical'))`
    `login_form = LoginForm()`
`if login_form.validate_on_submit():`
        `user = User.query.filter_by(username = login_form.username.data).first()`
`if user and bcrypt.check_password_hash(user.password, login_form.password.data):`
            `login_user(user)`
`print(current_user.username)`
            `next_page = request.args.get('next')`
            `flash('Logged in!', 'success')`
`return redirect(next_page or url_for('historical'))`
`else:`
            `flash('Invalid username/password combination', 'danger')`
`return redirect(url_for('login'))`
`return render_template('login.html', login_form = login_form)`

/r/flask
https://redd.it/h9k6og
I made a Spotify playlist generator called Surprisify

#[Surprisify website](https://surprisify.me) / [Github Repo](https://github.com/StephenChou/Surprisify-Playlist-Generator)

So I recently finished my first project that's a playlist generator for Spotify. I found that I wasn't really too satisfied with the custom playlists made by Spotify, so I decided to make a web app that could help give some better and more obscure options.

#How it works
___

More info can be found on the site, but the process is simple. Follow through the Spotify authorization process (more info on data collection can be found in the privacy section) and log in with your Spotify account. After, you will be prompted with a page that asks you to enter a 'level', which denotes how obscure you want your music to be. If you enter anywhere from around 1-5, you'll probably end up with a playlist similar to what Spotify recommends for you. If you enter a level like 10 and higher, it'll yield music from artists relatively unknown to you, but still within your tastes (**The site make take a bit to process the playlist as the algorithm itself is pretty memory intensive. Also, if you do enter a very high number, however, it might contain music that completely detracts from your tastes and might take

/r/Python
https://redd.it/hknnvo
How do I make another model a required field for abstractbaseuser model?

Here's a basic outline of what I've got

class Address(models.Model):
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
primary_key=True,
)
address = models.CharField(
max_length=200,
)
city = models.CharField(
max_length=100,
)
state = USStateField()
zipcode = USZipCodeField

class CustomUser(AbstractBaseUser):
...
required_fields = [
#How would I structure this to make the fields in Address required when


/r/django
https://redd.it/1055y71
P New tokenization method improves LLM performance & context-length by 25%+

I've been working on this new tokenization method to optimally represent text with fewer tokens than current methods. It's MIT licensed.

Code at Github.

Test it out.

The general-english-65535 vocabulary, and the code versions are already complete. The general-english-32000 should be finished within a few hours. Then I'm going test a non-greedy version which should do even better.

Intro from README:

tokenmonster is a novel approach to tokenization with broad-ranging use potential, but its primary motivation is to increase the inference speed and context-length of large language models by choosing better tokens. By selecting more optimal tokens, text can be represented with 20-30% less tokens compared to other modern tokenizing methods, increasing the speed of inference, training and the length of text by 20-30%. The code-optimized tokenizers do even better, see it for yourself.

I also believe that tokenmonster vocabularies will improve the comprehension of Large Language Models. For more details see How and Why.

## Features

Longer text generation at faster speed
Determines the optimal token combination for a greedy tokenizer (non-greedy support coming)
Successfully identifies common phrases and figures of speech
Works with all languages and formats, even binary
Quickly skims over HTML tags, sequential spaces, tabs, etc. without wasting context
Does not require normalization

/r/MachineLearning
https://redd.it/13gdfw0
fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU

What My Project Does

Fastplotlib is a next-gen plotting library that utilizes Vulkan, DX12, or Metal via WGPU, so it is very fast! We built this library for rapid prototyping and large-scale exploratory scientific visualization. This makes fastplotlib a great library for designing and developing machine learning models, especially in the realm of computer vision. Fastplotlib works in jupyterlab, Qt, and glfw, and also has optional imgui integration.

GitHub repo: https://github.com/fastplotlib/fastplotlib

Target audience:

Scientific visualization and production use.

Comparison:

Uses WGPU which is the next gen graphics stack, unlike most gpu accelerated libs that use opengl. We've tried very hard to make it easy to use for interactive plotting.


Our recent talk and examples gallery are a great way to get started!
Talk on youtube: https://www.youtube.com/watch?v=nmi-X6eU7Wo
Examples gallery: https://fastplotlib.org/ver/dev/gallery/index.html

As an aside, fastplotlib is not related to matplotlib in any way, we describe this in our FAQ:
https://fastplotlib.org/ver/dev/userguide/faq.html#how-does-fastplotlib-relate-to-matplotlib

If you have any questions or would like to chat, feel free to reach out to us by posting a GitHub Issue or Discussion! We love engaging with our community!


/r/Python
https://redd.it/1iidlui
iommi 7.19.0 released

New hero page: https://iommi.rocks/

- A new system for advanced layouts for forms and tables. Example: https://docs.iommi.rocks/cookbook_forms.html#how-do-i-make-complex-layouts-for-forms
- A manually drag-and-drop reorderable feature for EditTable
- Tables will automatically pick up sort order from your queryset

And a bunch of other minor features and bug fixes of course.

/r/django
https://redd.it/1oeq25m