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
R SEEM: Segment Everything Everywhere All at Once

We introduce SEEM that can Segment Everything Everywhere with Multi-modal prompts all at once. SEEM allows users to easily segment an image using prompts of different types including visual prompts (points, marks, boxes, scribbles and image segments) and language prompts (text and audio), etc. It can also work with any combinations of prompts or generalize to custom prompts!

​

https://preview.redd.it/8pkzou248rta1.png?width=1265&format=png&auto=webp&v=enabled&s=644f4e560f4e1f40a9cbd19f172af1165bae94d0

Play with the demo on GitHub! https://github.com/UX-Decoder/Segment-Everything-Everywhere-All-At-Once

We emphasize 4 important features of SEEM below.

1. Versatility: work with various types of prompts, for example, clicks, boxes, polygons, scribbles, texts, and referring image;
2. Compositionaliy: deal with any compositions of prompts;
3. Interactivity: interact with user in multi-rounds, thanks to the memory prompt of SEEM to store the session history;
4. Semantic awareness: give a semantic label to any predicted mask;

🔥Click, scribble to mask

With a simple click or stoke from the user, we can generate the masks and the corresponding category labels for it.

​

https://preview.redd.it/tymnl8a58rta1.png?width=1732&format=png&auto=webp&v=enabled&s=a2101364cf8b85f9e114f9cae09c1078f38f030b

🔥Text to mask

SEEM can generate the mask with text input from the user, providing multi-modality interaction with human.

​

https://preview.redd.it/jh6h3fb68rta1.png?width=1708&format=png&auto=webp&v=enabled&s=44c628544cf6f19bb4844d2aa8eafdb6e7040fe0

🔥Referring image to mask

With a simple click or stroke on the referring image, the model is able to segment the objects with similar semantics on the target images.

​

https://preview.redd.it/vgzrp0y78rta1.png?width=1724&format=png&auto=webp&v=enabled&s=8d08dea79b5de287e801932c4d7a9ca5b8647124

SEEM understands the spatial relationship very well. Look at the three

/r/MachineLearning
https://redd.it/12lf2l3
SQLalchemy question

Say for instance I have two classes. A User and Sport class. They are defined as below:

class User(UserMixin, db.Model):
__tablename__ = "users"

id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(32), index=True, unique=True)

sport_id = db.Column(db.Integer, db.ForeignKey("sports.id"))
attended_sport = db.Column(db.Boolean, default=False)




class Sport(db.Model):
__tablename__ = "sports"

id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(32))
users = db.relationship("User", backref="sport")
nominal_submitted = db.Column(db.Boolean)



To track the students I have two nominal rolls. One to track the students (let's say by their classrooms) and one for the sports teacher to submit once they have conducted their sport. If the sports nominal roll is submitted, I want the classroom tracker to say if the user attended or not. If the nominal roll is not submitted, I want the tracker to say 'Nominal not submitted'. What would be the best way of going about doing this?

Is there a query I can use - a left join perhaps to capture this query?

/r/flask
https://redd.it/12lrym2
How to assign a function to a field in models.py

So im making a model for the admin page, there is a field

url = models.CharField(maxlength=255, unique=True, verbosename="Download")

in models.py that i want to call a function download_file for downloading a .txt file when clicked on.

How do I assign a function to the field(the url field shows the url while in admins page)? Thanks!

/r/django
https://redd.it/12lu4s1
Pulling Last 3 Comments from database

I am trying to query my database and pull the last (3) comments from the database and am running into some issues.

Models.py

class Comment(models.Model):
post = models.ForeignKey(Post, relatedname="comments",ondelete=models.CASCADE)
name = models.ForeignKey(User, ondelete=models.CASCADE)
body = RichTextUploadingField(blank=True, null=True)
date
added = models.DateTimeField(default=timezone.now)

def str(self):
return '%s - %s' % (self.post.title, self.name)

views.py

def base(request):
lastthreecomments = Comment.objects.orderby('-dateadded'):3
context = {
'lastthreecomments' : lastthreecomments
}
return render(request, 'blog/base.html', context)

base.html

{% for comment in lastthreecomments %}
<li>{{ comment.body}}</li>


/r/djangolearning
https://redd.it/12linbg
FLASK APP CAPTURE NOT WORKING WHEN DEPLOYED ON SERVER



I know nothing of Back-end Web development I just registered for a just for fun hackathon now My app works fine on local machine but when i deploy it on the server it fails to get the camera feed\` Given Below is the app.py file base.html ExecersicebicepCurl.html and bicepcurl.py **this is app.py**

import time
import cv2
from flask import Flask, render_template, Response
import mediapipe as mp
import numpy as np

from project import exerciseAI, yogaAI

#-----------------Routing----------------------------------

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/exercise/biceps-curl')
def exerciseBicepsCurl():
return render_template('exerciseBicepsCurl.html')

@app.route('/exercise/push-ups')
def exercisePushUps():

/r/flask
https://redd.it/12luau3
Release: NiceGUI 1.2.7 with ui.download, easier color definitions, "aggrid from pandas dataframe" and much more

With 21 contributors the just released NiceGUI 1.2.7 is again a wonderful demonstration of the strong growing community behind our easy to use web-based GUI library for Python. NiceGUI has a very gentle learning curve while still offering the option for advanced customizations. By following a backend-first philosophy you can focus on writing Python code. All the web development details are handled behind the scenes.


### New features and enhancements
- introduce `ui.download`
- introduce color arguments for elements like ui.button that accept Quasar, Tailwind, and CSS colors
- allow running in Python’s interactive mode by auto-disabling reload
- allow creating ui.aggrid from pandas dataframe
- fix navigation links behind reverse proxy with subpath
- allow sending "leading" and/or "trailing" events when throttling
- raise an exception when hiding internal routes with app.add_static_files
- add “dark” color to ui.colors

### Documentation
- enhance Trello "drag and drop" example to use a ToDo data model
- add workaround to docs for native mode when WebView2Loader.dll fails load
- add documentation and demo about element borders inside a ui.card
- add hint about exception when running executable with no console on Windows

Of course the release also includes some bugfixes (see release notes for details). Thanks to everyone who was involved in making this release happen.

/r/Python
https://redd.it/12m03v5
Logging code mess

Way overdue for me but I started getting a lot more detailed with my logging. I'm finding it really clutters up the code though. Are there any best practices people use? When I have a two line method that has another two lines for logging it just starts feeling clunky.

Is there a way to be more elegant about it or is this just how it is with production code?

Alternatively are there any good code repos you guys can point me to that you think implement this stuff well?

/r/Python
https://redd.it/12lzpvi
How do you guys handle pandas and its sh*tty data type inference

I often like to dump CSVs with 100s of columns and millions of rows into python pandas. and I find it very very frustrating when it gets various data types for columns wrong. nothing helps

including `infer_objects().dtypes` and `convert_dtypes().dtypes`

how do you guys auto-detect dtypes for your columns?

is there a better library out there ?

/r/Python
https://redd.it/12m2gn8
[Crosspost] Introducing BungIO - a python bungie.net / destiny 2 api wrapper

Original Post: https://www.reddit.com/r/DestinyTheGame/comments/12lt3f1/introducing_bungio_a_python_bungie_api_wrapper/

---

**Features**

* Python 3.10+
* Asynchronous
* 100% typed and raw api coverage
* Ratelimit compliant
* Manifest support
* OAuth2 support
* Easily used in combination with other libraries like FastApi and discord wrappers


**Github**: https://github.com/Kigstn/BungIO

**Docs & Getting Started**: https://bungio.readthedocs.io/en/latest/

**Guides**: https://bungio.readthedocs.io/en/latest/Guides/basic/

---

While the bungie api is very extensive with a **lot** of functionality, it is IMO very confusing for new users. It also has a bunch of inconsistencies and suboptimal documentation. So as a side project, I've been working on making it more accessible for new people and api veterans.

Fast forward a few months, I'm ready to share BungIO with you all. I've been using it for my personal discord bot for ~half a year now and hopefully ironed out all the major kinks. It is designed to be easy to use, but still requires you to loosely know the api.


## Full API Coverage
What sets this library apart from other projects is that it has full api coverage - every single route is fully typed and returns fully typed python classes! And better yet, the api is automatically generated from the api spec bungie publishes. This means when there is an update to the api, it needs literally one button click from me to update

/r/Python
https://redd.it/12m2kpe
Can I add column to the result of a query?

I query a table like this:


check = Example.query.filter_by(example_attribute=1).all()

I get something in return that looks like this:

[Example('1','something', something again')]

Can I add to this so that it will look like this:

[Example('1', 'something', 'something again', 'another something')]

I tried this:
for x in check:
x.add_columns({'added column': 'another something'})

and that doesn't work.


Am I supposed to JSON.dumps this and then add it?

/r/flask
https://redd.it/12ley46
Pdfkit vs weasyprint ?

I have a pretty heavy website and want to generate pdf tickets , can be up to 20 per user per order, I already have pdfkit installed and working nicely with a small users number. But as my website grows I ask myself what is the better option between those two? Or is there a better third option …

My main concern is scalability and performance, my setup is a docker compose with django and celery for async pdf generation, hosted on aws elastic beanstalk with their auto scaling.

Can someone share his experience with pdf generation in django ?

Thanks guys for reading

/r/django
https://redd.it/12m7t68
Django REST Framework's TokenAuthentication VS JWTs

Hello guys, can someone explain why they would prefer one over the other? In terms of security, use case etc.

/r/django
https://redd.it/12mhff1
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/12mirgo
How to generate URL from @app.route url in FLASK?



I have a Flask code with decorator u/app.route(/bestApp) to fetch my data from Fetch API javascript.

this is my app.py :

&#x200B;

&#x200B;

@app.route('/bestApp', methods=['GET', 'POST'])

def bestapp():

app_data = AppDataFromUrl(app_url)

json.dumps(app_data)

permitted_directory='static/assets/upload/'

return send_from_directory(directory=permitted_directory, path=filename,as_attachment=True)

&#x200B;

&#x200B;

and this is my script.js

&#x200B;

&#x200B;

async function getExtract() {

try {

const response = await fetch("/bestApp", {

method: "post",

body: new FormData(document.querySelector(".testform")),

});

&#x200B;

console.log(response);



}

&#x200B;

&#x200B;



whenever i download my file, it works but the problem is the link that shown in browser is like “http://127.0.0.1:5000/bestApp

how to convert http://127.0.0.1:5000/bestApp to normal URL? such http://127.0.0.1:5000/42342jnkjsahdkajsda87391237921dask.

I don’t wanna use Blob Object Url or Data URI.

/r/flask
https://redd.it/12kkjfd
This week I made my first ever python script! It scrapes and translates a single Japanese website for hotel bookings asynchronously. Please come take a look :)

There is a hotel in Japan that will give you the insanely low price of $40 per night if you book a 30 day chunk all at once. Their site only lets you search a single location one day at a time though, so I decided to make this and learn everything from scratch along the way. The most ironic part is, I didn't find a single booking! I think they discontinued the offer... I was going to make a frontend with English translations for regular use too...


I'm openly accepting tips and advice on how to design these things better. It's probably pretty simple for you, but it took me awhile to figure out! Eventually I'd like to swap careers into tech :) If you have any ideas for what to make next be sure to leave your suggestion!


The code on github: https://github.com/Gornel/apa\_scraper/blob/main/list\_gatherer.py
A youtube of the first time I ran it: https://www.youtube.com/watch?v=cGUOLdaKBuE

/r/Python
https://redd.it/12m6obx