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
url_for() generated dynamics link for routes and assets in js, css file?

so I want to request a route from js code which i am serving from static... is there no way to insert dynamically generated link in js code??

/r/flask
https://redd.it/13638ub
How should I send requests to another API using DRF?

Should I use requests built-in python library or there is a special instruments to send requests to another API in APIView class?

/r/djangolearning
https://redd.it/136d4kg
Should I build Backend or Frontend first?

I'm using Django Rest Framework for the backend and React for the front-end.

Which should I build first for a Full-Stack project.

/r/django
https://redd.it/136lg76
Best practice for model id/pk?

So I'm starting a new Django project, and I want to get this right.

What's the best practice for model IDs?

1. id = models.UUIDField(default = uuid.uuid4, unique = True, primary_key = True)
2. id = models.UUIDField(default = uuid.uuid1, unique = True, primary_key = True)
3. Just use the default auto-increment pk (i.e. not define any specific primary key field)

I'm leaning strongly towards 2, as I heard that it's impossible to get a collision, since UUID1 generates a UUID from timestamp.

Problem with 3 is that I might need to use it publicly, so sequential IDs are no bueno.

What is the best practice for this?

/r/django
https://redd.it/136c4qb
[N] OpenLLaMA: An Open Reproduction of LLaMA

https://github.com/openlm-research/open_llama

> We train our models on the RedPajama dataset released by Together, which is a reproduction of the LLaMA training dataset containing over 1.2 trillion tokens. We follow the exactly same preprocessing steps and training hyperparameters as the original LLaMA paper, including model architecture, context length, training steps, learning rate schedule, and optimizer. The only difference between our setting and the original one is the dataset used: OpenLLaMA employs the RedPajama dataset rather than the one utilized by the original LLaMA.

/r/MachineLearning
https://redd.it/136exj2
Recommendations are not shown

**result.html**

`<!DOCTYPE html>`
`<html lang="en">`
`<head>`
    `<meta charset="UTF-8">`
    `<meta http-equiv="X-UA-Compatible" content="IE=edge">`
    `<meta name="viewport" content="width=device-width, initial-scale=1.0">`
    `<title>Result</title>`
`</head>`
`<body>`
    `<h1>Result</h1>`
    `<p id ="emotion">Emotion: {{ emotion }}</p>`
    `<p id ="gender">Gender: {{ gender }}</p>`
    `<button onclick="recommendation('{{ gender }}', '{{ emotion }}')">Recommendation</button>`
    `<div id="suggested"></div>`
    `<script>`
`window.onload = function() {`
`var gender = "{{ gender }}";`
`var emotion = "{{ emotion }}";`
`recommendation(gender, emotion);`
`document.getElementById("recommendBtn").addEventListener("click", function() {`
`recommendation(gender, emotion);`
        `});`
      `}`
`</script>`

`</body>`
`</html>`

[**app.py**](https://app.py)

`@app.route('/resultpage')`
`def resultpage():`
`gender = request.args.get('gender')`
`emotion = request.args.get('emotion')`
`return render_template('result.html', gender=gender, emotion=emotion)`

**app.js**

`function recommendation(gender, emotion){`
`var animePlaylist = '';`
`if(emotion == 'Angry'){`
`if(gender == 'Male'){`
`animePlaylist = 'https://myanimelist.net/anime/genre/36/Slice_of_Life';`
    `}`
`else if(gender == 'Female'){`
`animePlaylist = 'https://myanimelist.net/anime/genre/1/Action';`
    `}`
  `}`
`else if(emotion

/r/flask
https://redd.it/136wsxg
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/1373x63
Resources To Learn DRF

I am struggling to learn DRF i have started the course from coursera but it is not going good so can anyone suggest me some resource to learn DRF

/r/django
https://redd.it/136wth9
Discussion: Mark Zuckerberg on Meta's Strategy on Open Source and AI during the earnings call

During the recent earnings call, Mark Zuckerberg answered a question from Eric Sheridan of Goldman Sachs on Meta's AI strategy, opportunities to integrate into products, and why they open source models and how it would benefit their business.

I found the reasoning to be very sound and promising for the OSS and AI community.

The biggest risk from AI, in my opinion, is not the doomsday scenarios that intuitively come to mind but rather that the most powerful AI systems will only be accessible to the most powerful and resourceful corporations.

Quote copied from Ben Thompson's write up on Meta's earning in his Stratechery blog post which goes beyond AI. It's behind a paywall but I highly recommend it personally.

Some noteworthy quotes that signal the thought process at Meta FAIR and more broadly

We’re just playing a different game on the infrastructure than companies like Google or Microsoft or Amazon
We would aspire to and hope to make even more open than that. So, we’ll need to figure out a way to do that.
...lead us to do more work in terms of open sourcing, some of the lower level models and tools
Open

/r/MachineLearning
https://redd.it/1373nhq
D Oblivus Cloud | Scalable GPU servers from $0.29/hr

Greetings r/MachineLearning!

This is Doruk from Oblivus, and I'm excited to announce the launch of our platform, Oblivus Cloud. After more than a year of beta testing, we're excited to offer you a platform where you can deploy affordable and scalable GPU virtual machines in as little as 30 seconds! We believe that Oblivus Cloud is the perfect alternative to other cloud service providers when it comes to training your ML models.

https://oblivus.com/cloud

🤔 What sets Oblivus Cloud apart?

At the start of our journey, we had two primary goals in mind: to democratize High-Performance Computing and make it as straightforward as possible. We understand that maintaining GPU servers through major cloud service providers can be expensive, with hidden fees adding to the burden of running and maintaining servers.

Additionally, the cloud can sometimes be overly complex for individuals who don't have much knowledge but still require powerful computing resources.

That's why we decided to create a platform that offers affordable pricing, easy usability, and high-quality performance. Oblivus Cloud provides just that - a simple, affordable, and high-quality alternative for anyone in need of powerful computing resources.

 Features

Oblivus Cloud comes packed with a wide range of features to make your experience smooth, seamless, and fully customizable. Here are some

/r/MachineLearning
https://redd.it/1370xg9
Build a full stack social network - Django/DRF/Vue3/Tailwind - Free YouTube Series

Hey guys,
a few weeks ago I started publishing my newest course on my YouTube channel.

In this course, you will learn how to build a social network from scratch using Django with Django Rest Framework for the backend, and the frontend will be built using Vue and Tailwind.

Some of the features of the social network:
\-Authentication with jwt
\-Posts with attachments (showing on your feed, your profile and similar).
\-Direct messaging
\-Friends (sending/accepting friend requests)
\-Liking/discussing posts

So far, I have posted 4 parts with a total of almost 4 hours of content. And much more are coming :-D
I hope this sounds interesting and that it can help some of you.

If you're interested, you can find the playlist here:
https://www.youtube.com/playlist?list=PLpyspNLjzwBlobEvnZzyWP8I-ORQcq4IO


PS, I would love it if you subscribed to my channel if you want more content like this :-D

/r/djangolearning
https://redd.it/137c38x
ML model RAM over usage issue

Hi everyone, I am having an issue of RAM over usage with my ML model. My model is based on Tfidf+Kmeans algo, and uses flask + gunicorn architecture.

I have multiple gunicorn workers running on my server to handle parallel requests. The issue is that the model is not being shared b/w workers. Instead, it makes a copy of itself for each worker.

Since the model is quite big in size, this is consuming a lot of RAM. How do I solve this issue such that the model is shared between workers without being replicated?

/r/flask
https://redd.it/137ec9y
Are there any working examples I can download?

I know there are a number of tutorials but I was wondering if there are any working examples I can download of say, a basic bootstrap form.

Thanks

/r/flask
https://redd.it/137ko94
(Failed - but working 100%) Interview challenge

Recently I did not even make it to the interview due to the technical team not approving of my one-way directory sync solution.

I want to mention that I did it as requested and yet I did not even get a feedback over the rejection reason.

Can someone more experienced take a glance and let me know where \\ what I did wrong? pyAppz/dirSync.py at main · Eleuthar/pyAppz (github.com)

Thank you in advance!

&#x200B;

LE: I much appreciate everyone's feedback and I will try to modify the code as per your advice and will revert asap with a new review, to ensure I understood your input.

/r/Python
https://redd.it/137gvt9
Creating 2fa with pyotp

I have a flask app that I'm trying to add a 2fa option to. I'm using pyotp to generate a code that will be sent via email.

The user signs in normally (email, password) and and if they've opted-in to 2fa they are then redirected to a page asking them to submit the security code they received in an email.

The challenge I'm facing is figuring out how I can carry the user object info to the 2fa route so that if they enter the correct code I can login\_user(user)

If they enter the correct email and password but the wrong code I need to retain the fact that they entered the email and password correctly on their following attempts.

There's a login route, and a 2fa code route.

Currently I have the 2fa code generated when the user lands on the 2fa route, there's a function called otp() that creates the one time password:


```
@app.route("/twofactor", methods=\['GET', 'POST'\])
def twofactor():
if current\_user.is\_authenticated:
return redirect(url\_for('login'))
else:
x = otp()
form=TwoFactor()
if form.validate\_on\_submit():


/r/flask
https://redd.it/137lqpb