leonid, to python German
@leonid@norden.social avatar

Gibt es gute Hostingdienste, um eine Django/Python-App ähnlich einfach wie PHP zu hosten?

djangobrew, to django
@djangobrew@fosstodon.org avatar

New Django Brew episode alert! 🎧 https://djangobrew.com

In Episode 2, Sudsy Forms and Spicy Takes 🔥, we discuss Django Forms and our experiences with them, helpful third-party libraries, and more!

We also have some hot takes, try to pronounce the longest place name on Earth, and chat about the best post-apocalyptic coffee. 🫣

Subscribe in your podcast app and listen now! If you ❤️ Django Brew, we’d appreciate 5 ⭐️ and a review wherever you get your podcasts!

dongheena, to python
@dongheena@fosstodon.org avatar
bbelderbos, to python
@bbelderbos@fosstodon.org avatar

In you can use sub() from the "re" module to do regex string replacing.

If you want to keep a count of the number of replacements done as well, you can use subn() which returns a tuple of the new (replaced) string and the number of replacements made.

For example:

joe, to ai

A few weeks back, I thought about getting an AI model to return the “Flavor of the Day” for a Culver’s location. If you ask Llama 3:70b “The website https://www.culvers.com/restaurants/glendale-wi-bayside-dr lists “today’s flavor of the day”. What is today’s flavor of the day?”, it doesn’t give a helpful answer.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-12.29.28%E2%80%AFPM.png?resize=1024%2C690&ssl=1

If you ask ChatGPT 4 the same question, it gives an even less useful answer.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-12.33.42%E2%80%AFPM.png?resize=1024%2C782&ssl=1

If you check the website, today’s flavor of the day is Chocolate Caramel Twist.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-12.41.21%E2%80%AFPM.png?resize=1024%2C657&ssl=1

So, how can we get a proper answer? Ten years ago, when I wrote “The Milwaukee Soup App”, I used the Kimono (which is long dead) to scrape the soup of the day. You could also write a fiddly script to scrape the value manually. It turns out that there is another option, though. You could use Scrapegraph-ai. ScrapeGraphAI is a web scraping Python library that uses LLM and direct graph logic to create scraping pipelines for websites, documents, and XML files. Just say which information you want to extract and the library will do it for you.

Let’s take a look at an example. The project has an official demo where you need to provide an OpenAI API key, select a model, provide a link to scrape, and write a prompt.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-12.35.29%E2%80%AFPM.png?resize=1024%2C660&ssl=1

As you can see, it reliably gives you the flavor of the day (in a nice JSON object). It will go even further, though because if you point it at the monthly calendar, you can ask it for the flavor of the day and soup of the day for the remainder of the month and it can do that as well.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-1.14.43%E2%80%AFPM.png?resize=1024%2C851&ssl=1

Running it locally with Llama 3 and Nomic

I am running Python 3.12 on my Mac but when you run pip install scrapegraphai to install the dependencies, it throws an error. The project lists the prerequisite of Python 3.8+, so I downloaded 3.9 and installed the library into a new virtual environment.

Let’s see what the code looks like.

You will notice that just like in yesterday’s How to build a RAG system post, we are using both a main model and an embedding model.

So, what does the output look like?

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-09-at-2.28.10%E2%80%AFPM.png?resize=1024%2C800&ssl=1

At this point, if you want to harvest flavors of the day for each location, you can do so pretty simply. You just need to loop through each of Culver’s location websites.

Have a question, comment, etc? Please feel free to drop a comment, below.

https://jws.news/2024/how-to-use-ai-to-make-web-scraping-easier/

#AI #ChatGPT #llama3 #LLM #Ollama #Python #ScrapegraphAi #WebScraping

fallenhitokiri, to python
@fallenhitokiri@social.screamingatmyscreen.com avatar

“Members of any membership class with voting rights must affirm each year…“

A drama in three acts

  • register: (captcha) I think I should have an account already?!
  • login: (captcha) obviously not, I could register the mail address
  • no idea, same page as before without login button
  • click link in email: „obviously“ not a member

I have no idea what’s going on.
I’m not sure I have the energy to care.
I might simply reassign the money to another org.

Login
Don’t know what to do
Not a member?

adamchainz, to python
@adamchainz@fosstodon.org avatar

✍️ New post covering a small helper to return all subclasses of a given class.

https://adamj.eu/tech/2024/05/10/python-all-subclasses/

henryiii, to python
@henryiii@fosstodon.org avatar

Python 3.13 beta 1 is out, which means it's time for my yearly post on what's new: https://iscinumpy.dev/post/python-313/

irfan, to django

Hmm I've only ever built sites using , bcos I'm most good at and I'm just super familiar with all the features (and quirks) of Django and it's been great, but honestly being good at only Django (when it comes to web dev) does gimme huge impostor syndrome cos I know fuck all when people talk about and whatnot :(

Maybe I can learn how to build a site using so I too can speak gibberish lingo I never understood before with other fellow programmers?

RE: https://social.lol/users/bw/statuses/112414344202116592

henryiii, to python
@henryiii@fosstodon.org avatar

This feature of uv is not talked about enough:

uv pip install --exclude-newer 2020-01-01 -r requirements.txt

I was able to recover and build a project untouched for many years using this easily!

brianb, to python
@brianb@fosstodon.org avatar

Is there a better interface for interacting with the breakpoint() debugger in a script rather than use c/n to go line by line?

textovervideo, to python
@textovervideo@fosstodon.org avatar

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.

https://pyinfra.com/

treyhunner, to python
@treyhunner@mastodon.social avatar

The bisect module has an implementation of binary search for you.

Read the full article: Python Big O: the time complexities of different data structures in Python
https://trey.io/d8D57O

#Python

pyOpenSci, to random
@pyOpenSci@fosstodon.org avatar

pip install xgi

And get started streamlining your processes for working with higher-order networks from start to finish! XGI is part of the ecosystem, and excels at many things, including:

🔍 Analyzing higher-order networks with measures and algorithms
🧰 Manipulating node and edge statistics in a flexible and customizable way
🎨 Drawing higher-order networks in a variety of visually striking ways

📄 XGI docs: https://xgi.readthedocs.io/en/stable/

talkpython, to python
@talkpython@fosstodon.org avatar

Kicking off another @talkpython live stream in a few minutes! Join us and be part of the show with @mkennedy and guests. https://talkpython.fm/stream/live

treyhunner, to python
@treyhunner@mastodon.social avatar

What are your favorite one liners?

talkpython, to python
@talkpython@fosstodon.org avatar

Kicking off another @talkpython live stream in a few minutes! Join us and be part of the show with @mkennedy and guests. https://talkpython.fm/stream/live

ethauvin, to python
@ethauvin@mastodon.social avatar
Posit, to python
@Posit@fosstodon.org avatar

RStudio IDE and Posit Workbench version 2024.04.0, code-named “Chocolate Cosmos, is now out! 🎉

The latest release comes with several updates, such as bundling Quarto version 1.4, VS Code updates, and support for R 4.4.

Learn more: https://posit.co/blog/rstudio-2024-04-0-whats-new/

#RStats #Python #Quarto #QuartoPub

chiefgyk3d, to python
@chiefgyk3d@social.chiefgyk3d.com avatar

I was up late trying to figure out a stupid issue I was having with the Crowdstrike API so I didn't stream on twitch last night, hoping to do a stream tonight. I think they took a feature out my team was actually using which would allow me to contain a device and make a note that could be viewed in the dashboard.

#Coding #Crowdstrike #Python #Dev #InfoSec #Cybersecurity

joe, (edited ) to ai

Back in January, we started looking at AI and how to run a large language model (LLM) locally (instead of just using something like ChatGPT or Gemini). A tool like Ollama is great for building a system that uses AI without dependence on OpenAI. Today, we will look at creating a Retrieval-augmented generation (RAG) application, using Python, LangChain, Chroma DB, and Ollama. Retrieval-augmented generation is the process of optimizing the output of a large language model, so it references an authoritative knowledge base outside of its training data sources before generating a response. If you have a source of truth that isn’t in the training data, it is a good way to get the model to know about it. Let’s get started!

Your RAG will need a model (like llama3 or mistral), an embedding model (like mxbai-embed-large), and a vector database. The vector database contains relevant documentation to help the model answer specific questions better. For this demo, our vector database is going to be Chroma DB. You will need to “chunk” the text you are feeding into the database. Let’s start there.

Chunking

There are many ways of choosing the right chunk size and overlap but for this demo, I am just going to use a chunk size of 7500 characters and an overlap of 100 characters. I am also going to use LangChain‘s CharacterTextSplitter to do the chunking. It means that the last 100 characters in the value will be duplicated in the next database record.

The Vector Database

A vector database is a type of database designed to store, manage, and manipulate vector embeddings. Vector embeddings are representations of data (such as text, images, or sounds) in a high-dimensional space, where each data item is represented as a dense vector of real numbers. When you query a vector database, your query is transformed into a vector of real numbers. The database then uses this vector to perform similarity searches.

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-08-at-2.36.49%E2%80%AFPM.png?resize=665%2C560&ssl=1

You can think of it as being like a two-dimensional chart with points on it. One of those points is your query. The rest are your database records. What are the points that are closest to the query point?

Embedding Model

To do this, you can’t just use an Ollama model. You need to also use an embedding model. There are three that are available to pull from the Ollama library as of the writing of this. For this demo, we are going to be using nomic-embed-text.

Main Model

Our main model for this demo is going to be phi3. It is a 3.8B parameters model that was trained by Microsoft.

LangChain

You will notice that today’s demo is heavily using LangChain. LangChain is an open-source framework designed for developing applications that use LLMs. It provides tools and structures that enhance the customization, accuracy, and relevance of the outputs produced by these models. Developers can leverage LangChain to create new prompt chains or modify existing ones. LangChain pretty much has APIs for everything that we need to do in this app.

The Actual App

Before we start, you are going to want to pip install tiktoken langchain langchain-community langchain-core. You are also going to want to ollama pull phi3 and ollama pull nomic-embed-text. This is going to be a CLI app. You can run it from the terminal like python3 app.py "<Question Here>".

You also need a sources.txt file containing the URLs of things that you want to have in your vector database.

So, what is happening here? Our app.py file is reading sources.txt to get a list of URLs for news stories from Tuesday’s Apple event. It then uses WebBaseLoader to download the pages behind those URLs, uses CharacterTextSplitter to chunk the data, and creates the vectorstore using Chroma. It then creates and invokes rag_chain.

Here is what the output looks like:

https://i0.wp.com/jws.news/wp-content/uploads/2024/05/Screenshot-2024-05-08-at-4.09.36%E2%80%AFPM.png?resize=1024%2C845&ssl=1

The May 7th event is too recent to be in the model’s training data. This makes sure that the model knows about it. You could also feed the model company policy documents, the rules to a board game, or your diary and it will magically know that information. Since you are running the model in Ollama, there is no risk of that information getting out, too. It is pretty awesome.

Have any questions, comments, etc? Feel free to drop a comment, below.

https://jws.news/2024/how-to-build-a-rag-system-using-python-ollama-langchain-and-chroma-db/

ThePSF, to python
@ThePSF@fosstodon.org avatar

Will you be at @pycon US this year? Join the fun and sign up to volunteer at the PSF Booth (or another location) for a couple of hours! Volunteering at is a great way to meet awesome folks in our community 🫶
https://us.pycon.org/2024/volunteers/volunteering/

fohrloop, to python
@fohrloop@fosstodon.org avatar

The new python 3.13 REPL looks so useful that I might be able to switch from IPython to it entirely!

https://treyhunner.com/2024/05/my-favorite-python-3-dot-13-feature/

skribe, to django
@skribe@aus.social avatar

Django peeps. I want to link my languages table (English, French, Chinese, etc) to the word classes (Nouns, Verbs, Adjectives, etc) table. It would be a many-to-many relationship, but I'm not sure whether to use a join table or the many-to-many model. What's the most Django way?

marsbarlee, to python
@marsbarlee@www.librepunk.club avatar

Woah! I’m giving a talk at titled “Paint by Numbers: A Retrospective on the ‘NumPy Comics’ and Under-Represented Skillsets in Documentation”.

A refreshingly honest tell-all on what went right, what went wrong and what went horribly wrong. 🥲 Check it out at the Documentation Summit, Sunday, May 19!

If you’ve never heard of the NumPy comics, check them out here! https://heyzine.com/flip-book/3e66a13901.html

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • InstantRegret
  • ngwrru68w68
  • Durango
  • Youngstown
  • slotface
  • mdbf
  • rosin
  • PowerRangers
  • kavyap
  • DreamBathrooms
  • normalnudes
  • vwfavf
  • hgfsjryuu7
  • cisconetworking
  • osvaldo12
  • everett
  • ethstaker
  • GTA5RPClips
  • khanakhh
  • tester
  • modclub
  • cubers
  • Leos
  • provamag3
  • All magazines