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
D Answer explainability and transparency with Retrieval Augmented Generation model

Hi everyone,

I've been exploring the fascinating world of Retrieval-Augmented Generation (RAG) systems, and their ability to combine large language models with retrieval mechanisms to provide accurate and contextually rich answers is truly impressive. However, I've been wondering about the explainability and transparency of the answers these models generate. Specifically, I'm curious about understanding which parts of the provided context are being used by the model to generate its answers.

Despite my efforts, I haven't been able to find much relevant research, articles, or public use cases on this topic. Is it just me, am I not googling using the appropriate keywords, or is there genuinely a lack of research in this area? I believe it's crucial to know how the model arrives at its answers, especially in applications where trust and verification of the information are important.

I'm eager to hear your thoughts and experiences. If you have worked with RAG or similar models, how do you ensure the answers are explainable and transparent? Any best practices or insights would be greatly appreciated.

Looking forward to your responses!

/r/MachineLearning
https://redd.it/1e77yul
Dodecaphony: Algorithmic Composition of Modern Classical Music

What does this project do?



My Python package is named after an alternative musical system. The vast majority of music is tonal (at least, in Western culture). In the 20th century, composers started to look for novel principles of music creation. Although some of these were based on the music of non-Western nations, some others were developed from scratch. The most famous of such musical paradigms is called the twelve-tone technique and it is also known as dodecaphony.



As a software developer, I am interested in dodecaphony, because it is logic-oriented and has many symmetries. I find it very suitable for combinatorial optimization.



So, I created a tool that takes YAML config as input and generates MIDI and WAV musical fragments in the twelve-tone technique. Given enough number of properly filled configs, it is possible to stack output fragments together and get a complete musical track.



This is a production-grade tool, not a toy project. With this tool, I released a 26-minutes album on Spotify and many other streaming platforms. However, main melodies for the album were written manually by myself and a lot of hard work was done with configs, but, nevertheless, the package really helped to generate background melodies. To read more

/r/Python
https://redd.it/1e6zh24
i need help with a project

hi there i am doing a project for my fullstack course but have come across an issue I am trying to make a detailed post view put once I added it to my URLs.py I get this error

Reverse for 'postdetail' with arguments '('DEAD-BY-DAYLIGHT’S-MYTHIC-TOME-EXPLORES-YUI-KIMURA-AND-THE-SPIRIT',)' not found. 1 pattern(s) tried: ['(?P<slug>[-a-zA-Z0-9]+)/\\Z']

and it is saying this line is giving me that error

<a href="{% url 'post_detail' post.slug %}" class="post-link black-text">


but when I delete this from my urls.py

path('<slug:slug>/', views.postdetail, name='postdetail'),




my page loads again how do I fix it

/r/django
https://redd.it/1e7dhlg
Stateful Objects and Data Types in Python: Pyliven

A new way to calculate in python!

If you have used ReactJS, you might have encountered the famous useState hook and have noticed how it updates the UI every time you update a variable. I looked around and couldn't find something similar for python. And hence, I built this package called **Pyliven**

**What My Project Does**

I have released the first version and as of now, it supports a stateful numeric data-type called LiveNum. It can be used to create dependent expressions which can be updated by just updating dependencies. The functionality is illustrated by a simple code block below:

a = LiveNum(3)
b = 2 * a
print(b) # 6

a.update(4)
print(b) # 8

It is also compatible with int and float type conversions.

**Target Audience**

The project is meant for use in production. Although for practical use cases, a lot of functionalities need to be build. So for now, this can be used for small/toy projects or people looking for a way

/r/Python
https://redd.it/1e7dg1h
Need help with User's API key management in flask app

I am currently working on a Flask App that I want users to use with an API key. I am providing a frontend where users can generate/revoke api keys. I want to know the best way to create a backend system for the api key management. I am aware that keys are not stored in plaintext, they should be hashed or encrypted, I am struggling to find good resources for this, I need to be able to query all of a user's keys to show them in the frontend. Right now this is what I am thinking:

The generate endpoint will take in a user_id, based on this user_id I will generate a jwt token (storing the user_id in the payload), this jwt token itself will serve as the api key. I need this because when validating an api key I do not want to go through all the hashes in the database, I can get the user_id and narrow down the search. I am also planning to encrypt the jwt token and store it in the database so it can be used to query a user's api keys from the frontend (encrypted jwt will be decrypted in the frontend),

/r/flask
https://redd.it/1e7678a
could somebody in here help me with MTV??

I created a file "routes.py" inside folder view, where all my routes (only routes, not their functions) are stored in the py file

eg:

from flask import Flask

app = Flask(name)


# Route for home
@app.route("/")
def home():
    return helloworld()


# Route for signup
@app.route("/signup", methods=["GET", "POST"])
def create
account():
    return signup()

now, how to import the routes.py module into my app.py module that contains the functions for the routes?

i have tried

from view.routes import hello_world (not working)

from view.routes import routes (not working)


please help me with it

/r/flask
https://redd.it/1e6wkvv
DETAIL: User does not have CONNECT privilege, Heroku Database Issues

Hi,

I am attempting to deploy a Django application on Heroku. I have created a PostgreSQL database for the app in Heroku and implemented it into the settings.py, but every time I try to access it from Django in any way I receive the following errors:

2024-07-20T05:00:24.595711+00:00 app[web.1]: connection to server at "c5flugvup2318r.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com" (44.209.39.179), port 5432 failed: FATAL: permission denied for database "postgres"

2024-07-20T05:00:24.595713+00:00 app[web.1]: DETAIL: User does not have CONNECT privilege.

And a 500 error.

This is an error I receive from running

user = authenticate(
request
,
username
=username,
password
=password)

All the this worked locally. I also am unable to make migrations to the database through heroku run python `manage.py` migrate.

I have tried manually changing permission through PostgreSQL but have been denied permission every time, and also have tried destroying and recreating my database. I have pretty much spent the last four hours on this with no resolution. If anyone has experienced a similar error or may have a potential solution, please let me know. If you need more information, also let me know.

Thank

/r/django
https://redd.it/1e7nyvn
Is Using Django Templates for Frontend Good Enough?

I'm trying to create a farm manager web app in Django. I am most definitely going to use it as the backend but I'm not so sure about as a frontend. I just want to see what people recommend for the frontend. I need to control users and a lot of agriculture data.

/r/django
https://redd.it/1e7onm4
When i want to create new environment . This happened

/r/IPython
https://redd.it/1e7ps8y
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

/r/Python
https://redd.it/1e7ibci
Most underrated part of a Django app

I think as soon as I hit production, logging instantly become the most valuable part of my Django app.

Any best practices I should know of or good libraries that help? I try to log as much as is necessary to reproduce and error. Besides errors I think the insides on bad requests that are no errors but probably bad UI (Validation messages are not clear enough) are also helpful.


/r/django
https://redd.it/1e7rjqx
Does Anybody Know How to Host an existing Django Project on Ubuntu

See title. I finished programming a website using Django, and I am ready to put it on a server, but I keep hitting dead ends. Does anybody know the steps I should take, or a website I should visit?

Edit: If it makes any difference, I am using a MySQL database. Also, I want this to be locally hosted.

/r/djangolearning
https://redd.it/1e75voa
Suddenly a package doesn't exist

I have a flask app that has been running fine for a couple of years. Today I tried to push an update to my host platform and the build failed because a package requirement could not be satisfied.

When I checked the logs I saw this error:

"ERROR: Could not find a version that satisfies the requirement install==1.3.5 (from versions: none)
ERROR: No matching distribution found for install==1.3.5"


Not recognizing the package and I looked into it and according to pypi.org that package doesn't exist.

I thought maybe it's some kind of dependency but I am unable to find any reference to it anywhere.

I removed it from my requirements.txt and tried to push again, now I received an error that said:

"Getting requirements to build wheel did not run successfully."

Does anyone have any idea of what could be happening here?

I went back and checked my recent updates and the package "install==1.3.5" was part of my requirements.txt for many months. I was able to push updates to my platform without issue and suddenly today the package doesn't exist and my app fails to build on my platform.

Any suggestions or knowledge you could share on what might be happening/a solution would

/r/flask
https://redd.it/1e7w9jl
Expose and deploy your Flask app from Linux virtual machine!

I'm new into coding and I want to expose my Flask app from my virtual machine so that when the user enters their password and username gets redirected. However, each time when I do it, there is an error in the console. Can you help me?

/r/flask
https://redd.it/1e7yre7
Django with Docker - access denied to volume

Anyone had issues running collectstatic inside a Docker container where your static files are mapped to a volume on the host? I keep getting permission denied.

I have done a bit of digging and the answer always seems to be 'give everything root privileges' which sounds a bit of a cop out.

I can run the command from outside via exec and have the files collect ok, but I will eventually also need to upload media to a shared volume and I'm assuming this is going to be an issue...

/r/django
https://redd.it/1e7yacx
Multiple Type of user login

I'm new to django. I have made an app where there are different type of users like vendors, clerks, delivery boys and simple users.

I have made different app for all of them.

I want them to have access to their app only. A vendor with his credentials cannot log into users account.

Each one of them have their own model.

/r/django
https://redd.it/1e87png
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1e89aai
AWS EC2 + RDS + S3 = so expensive, even with zero users

Hey folks!

I launched my SaaS project(and it has zero user) an he is my monthly cost:

AWS

Relational Database ServiceUSD - 17.91
Elastic Compute CloudUSD - 10.71
Virtual Private CloudUSD - 6.82
Route 53USD - 0.51
Simple Storage Service - 0.03

Total: 35.98$

Mailgul(email notification):

35$ - 50k monthly emails 10 domains

So it comes down to \~$70/mon

Two thoughts:

1. I used AWS because I new how to set it up quickly.
2. Mailgun was recommend to me by a friend. I though my project will get users, but unfortunately it is not getting any. I'm switching to a cheaper plan that is 15$ per month now.

Can you please recommend what is cheaper alternatives out there. I now data bases could get expensive, but in case I even didn't git 100 users and I'm already paying so much.

Thank you.

/r/django
https://redd.it/1e8dkwd
Dont really know how to structure/organize templates + static files in project.

I feel so much pain and cringe with my spaghetti ui/template but-functioning-as-for-now code

Dont know how to Connect all this insights or ideas into a "structured way" of doing things in Django UI part.

I have 3 different layouts one is full width other is with a drawer another is without the drawer.
There are elements/components/ in tables or forms that may be shared across apps.
From a DX perspective for JS code sometimes i prever "intra-file" script tag. Sometimes add it via Django Template Inheritance block feels ok. But also use webpack and may import js code directly to webpack entrypoint/entryfile.
My new best friend htmx and template-partials with or without the Carlton Gibson package

I would love if django provided an opinionated way of writing and storing html/js code and files. Taking into consideration the simple but diverse a fully functiong web Application could be in terms of ui related code and how easy it is to constantly repeat yourself and store code in all Parts of the project.

/r/django
https://redd.it/1e8eikq
I created a datestamp tool to add datestamps to your photos from metadata

# What My Project Does

I created a tool that extracts the date a photo was taken from the metadata and adds the datestamp to the photo. I was motivated to create this project, because I saw someone asking for a tool like this on a photography subreddit.

Flask was my web library of choice and pillow was used to extract metadata and edit the images. The frontend is a barebones HTML form without CSS and JavaScript. I am hosting this app on pythonanywhere.

# Target Audience

People who feel nostalgic about their old photos.

# Comparison

I haven't seen any web-hosted alternatives to this tool, but one possible option is to use the imagemagick CLI. My tool is more user friendly as it does not require the user to interact with a terminal application.

Repo: https://github.com/ch-iv/image-datestamp/

Website: https://datestamp.noivan.dev/

/r/Python
https://redd.it/1e82dqq