Skip to content

Commit fb79bfb

Browse files
authored
Merge branch 'master' into first-match
2 parents f5cabd1 + 7a74a81 commit fb79bfb

File tree

199 files changed

+37442
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+37442
-22
lines changed

add-to-path/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# How to Add Python to Path
2+
3+
Supporting materials for the Real Python tutorial [How to Add Python to PATH](https://realpython.com/add-python-to-path/).
4+
5+
Here you'll find a file for Windows and one for Linux and macOS. They have snippets and instructions distilled from the tutorials.
6+
7+
Additionally, you'll find some ways to set environment variables and modify `PATH` with PowerShell on Windows that aren't included in the tutorial.

add-to-path/linux-and-macos.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ------------------------------------
2+
# Add Path to PATH
3+
# ------------------------------------
4+
5+
# Make sure you use the right profile for your system
6+
$ export PATH="<PATH_TO_PYTHON>:$PATH"
7+
8+
# ------------------------------------
9+
# Add Path-Adding Operation to Profile
10+
# ------------------------------------
11+
12+
# Make sure you use the right profile for your system
13+
$ echo export PATH="<PATH_TO_PYTHON>:$PATH" >> ~/.profile
14+
# Reread profile to see effect in same session
15+
$ source ~/.profile
16+
17+
# ------------------------------------
18+
# Filtering Bad Paths from PATH
19+
# ------------------------------------
20+
21+
# View current PATH
22+
$ echo $PATH
23+
# Output:
24+
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:
25+
# /sbin:/bin:/usr/games:/usr/local/games
26+
27+
# View on separate lines by replacing colons with newlines
28+
$ echo $PATH | tr ":" "\n"
29+
# Output:
30+
# /usr/local/sbin
31+
# /usr/local/bin
32+
# /usr/sbin
33+
# /home/realpython/badpython
34+
# /usr/bin
35+
# /sbin
36+
# /bin
37+
# /usr/games
38+
# /usr/local/games
39+
40+
# Filter out certain lines with grep -v
41+
$ echo $PATH | tr ":" "\n" | grep -v 'badpython'
42+
# Output:
43+
# /usr/local/sbin
44+
# /usr/local/bin
45+
# /usr/sbin
46+
# /usr/bin
47+
# /sbin
48+
# /bin
49+
# /usr/games
50+
# /usr/local/games
51+
52+
# Replace newlines with colons
53+
$ echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"
54+
# Output:
55+
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
56+
# /usr/local/games
57+
58+
# Assign to PATH
59+
$ export PATH=`echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"`

add-to-path/windows.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# --------------------------------------------------
2+
# How to Add to `PATH` via GUI
3+
# --------------------------------------------------
4+
5+
<#
6+
7+
Once you've located your Python executable, open the Start menu and search
8+
for the _Edit the system environment variables_ entry, which opens up a
9+
_System Properties_ window. In the _Advanced_ tab, click on the button
10+
_Environment Variables_. There you'll see _User_ and _System_ variables,
11+
which you'll be able to edit.
12+
13+
In the section entitled _User Variables_, double-click on the entry that
14+
says _Path_. Another window will pop up showing a list of paths. Click the
15+
_New_ button and paste the path to your Python executable there. Once that's
16+
inserted, select your newly added path and click the _Move Up_ button until
17+
it's at the top.
18+
19+
That's it! You may need to reboot your computer for the changes to take
20+
effect, but you should now be able to call `python` from the command line.
21+
22+
#>
23+
24+
# --------------------------------------------------
25+
# Working With Environment Variables With PowerShell
26+
# --------------------------------------------------
27+
28+
# Set temporary environment variable (only active for current shell session)
29+
PS> $ENV:TEST = "VALUE"
30+
31+
# Set permanent environment variable (need to restart shell to take effect)
32+
PS> [Environment]::SetEnvironmentVariable("TEST", "VALUE", "User")
33+
34+
PS> cd ENV:
35+
PS> ls
36+
37+
<# OUTPUT
38+
39+
Name Value
40+
---- -----
41+
ALLUSERSPROFILE C:\ProgramData
42+
ANSICON 166x32766 (166x66)
43+
ANSICON_DEF 7
44+
APPDATA C:\Users\RealPython\AppData\Roaming
45+
AZ_ENABLED False
46+
...
47+
TEST VALUE
48+
...
49+
50+
#>
51+
52+
# View PATH
53+
PS> (cat ENV:PATH) -Split ";"
54+
55+
<# OUTPUT
56+
57+
C:\Program Files\PowerShell\7
58+
C:\Windows\system32
59+
C:\Windows
60+
C:\Windows\System32\WindowsPowerShell\v1.0\
61+
C:\Windows\System32\OpenSSH\
62+
63+
#>
64+
65+
# Append path to PATH
66+
PS> $ENV:PATH = "$ENV:PATH;C:\new\path"
67+
68+
# Prepend path to PATH
69+
PS> $ENV:PATH = "C:\new\path;$ENV:PATH"

chatterbot/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ChatterBot: Build a Chatbot with Python
2+
3+
This repository contains code related to the tutorial on [building a Python chatbot with ChatterBot](https://realpython.com/build-a-chatbot-python-chatterbot/).
4+
5+
Create and activate a [virtual environment](https://realpython.com/python-virtual-environments-a-primer/), then install the necessary dependencies:
6+
7+
```sh
8+
$ python -m venv venv
9+
$ source venv/bin/activate
10+
(venv) $ python -m pip install -r requirements.txt
11+
```
12+
13+
Then you can navigate into the folder `source_code_final/` and train and start the interactive command-line interface chatbot by running `bot.py`:
14+
15+
```sh
16+
(venv) $ cd source_code_final
17+
(venv) $ python bot.py
18+
```
19+
20+
After training, you'll see an interactive prompt that you can chat with:
21+
22+
```text
23+
> hi
24+
🪴 Welcome, friend 🤗
25+
> thanks for the green welcome
26+
🪴 I let you
27+
> you let me be here?
28+
🪴 It's a monsters!
29+
> did you mean monstera?
30+
🪴 The leafs that she had are getting dryer and dryer. But she’s also growing plenty of new ones
31+
> who?
32+
🪴 Do raindrops touch their leaves?
33+
> very philosophical!
34+
🪴 Lol
35+
> ;)
36+
🪴 I don't grow any crop at home
37+
> no crops in pots
38+
🪴 Ah, gotcha!
39+
```
40+
41+
The bot will learn from the replies you give and improve its accuracy. You can quit the interactive prompt by typing any of the `exit_conditions` defined in `bot.py`.
42+
43+
You'll find the code for each step of the tutorial in a separate folder. The folders also include a SQLite database that contains the different phases of training at each step. Because of this, you can inspect the project at different stages and notice how it evolves when you add more data and interactions.

chatterbot/requirements.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ChatterBot==1.0.4
2+
chatterbot-corpus==1.2.0
3+
click==8.1.3
4+
joblib==1.1.0
5+
mathparse==0.1.2
6+
nltk==3.7
7+
Pint==0.19.2
8+
pymongo==3.12.3
9+
python-dateutil==2.7.5
10+
pytz==2022.2.1
11+
PyYAML==3.13
12+
regex==2022.9.11
13+
six==1.16.0
14+
SQLAlchemy==1.2.19
15+
tqdm==4.64.1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from chatterbot import ChatBot
2+
from chatterbot.trainers import ListTrainer
3+
from cleaner import clean_corpus
4+
5+
6+
CORPUS_FILE = "chat.txt"
7+
8+
chatbot = ChatBot("Chatpot")
9+
10+
trainer = ListTrainer(chatbot)
11+
cleaned_corpus = clean_corpus(CORPUS_FILE)
12+
trainer.train(cleaned_corpus)
13+
14+
exit_conditions = (":q", "quit", "exit")
15+
while True:
16+
query = input("> ")
17+
if query in exit_conditions:
18+
break
19+
else:
20+
print(f"🪴 {chatbot.get_response(query)}")
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
9/15/22, 14:50 - Messages and calls are end-to-end encrypted. No one outside of this chat, not even WhatsApp, can read or listen to them. Tap to learn more.
2+
9/15/22, 14:49 - Philipp: Hi Martin, Philipp here!
3+
9/15/22, 14:50 - Philipp: I’m ready to talk about plants!
4+
9/15/22, 14:51 - Martin: Oh that's great!
5+
9/15/22, 14:52 - Martin: I've been waiting for a good convo about plants for a long time
6+
9/15/22, 14:52 - Philipp: We all have.
7+
9/15/22, 14:52 - Martin: Did you know they need water to grow?
8+
9/15/22, 14:52 - Philipp: I always thought that love and music was more than enough
9+
9/15/22, 14:53 - Philipp: But water makes sense
10+
9/15/22, 14:53 - Martin: Do you talk to your plants?
11+
9/15/22, 14:53 - Philipp: I do!
12+
9/15/22, 14:53 - Philipp: Some of them even have names
13+
9/15/22, 14:54 - Martin: What do they like to hear?
14+
9/15/22, 14:54 - Philipp: Motivational speeches
15+
9/15/22, 14:54 - Philipp: Or stories about plants that made it and are living outside now
16+
9/15/22, 14:54 - Martin: Oohhh 🥲
17+
9/15/22, 14:54 - Martin: Are you training them for independence?
18+
9/15/22, 14:56 - Philipp: Yeah! I want them to be strong and take care of themselves at some point
19+
9/15/22, 14:56 - Martin: That's heroic!
20+
9/15/22, 14:57 - Martin: Sounds like you're a great plant parent
21+
9/15/22, 14:57 - Philipp: Do you have any plant care pro tips?
22+
9/15/22, 14:58 - Martin: Ahh, idk i just leave them be...
23+
9/15/22, 14:58 - Martin: They are doing ok but not great
24+
9/15/22, 14:58 - Philipp: So they are independent already!
25+
9/15/22, 14:58 - Martin: I guess one tip would be to get plants that don't need much :P
26+
9/15/22, 14:58 - Philipp: Like plastic plants, for example?
27+
9/15/22, 14:59 - Martin: Haha, yes! Get independent plants!
28+
9/15/22, 14:59 - Martin: Plastic plants are the cream of the crop
29+
9/15/22, 14:59 - Martin: I haven't graduated to plastic plants yet
30+
9/15/22, 14:59 - Philipp: Cream of the crop?
31+
9/15/22, 15:00 - Philipp: I don't know what this means
32+
9/15/22, 15:01 - Martin: Crop is a cultivated plant that is grown on a large scale commercially, especially a cereal, fruit, or vegetable
33+
9/15/22, 15:01 - Martin: The cream must be the best of the best
34+
9/15/22, 15:01 - Martin: Or maybe just all of it blended together? ;p
35+
9/15/22, 15:02 - Martin: I don't grow any crop at home
36+
9/15/22, 15:02 - Martin: And no cream, in case you wondered
37+
9/15/22, 15:03 - Philipp: Ah, gotcha!
38+
9/15/22, 15:03 - Philipp: Let me show you something!
39+
9/15/22, 15:04 - Martin: I let you
40+
9/15/22, 15:06 - Philipp: <Media omitted>
41+
9/15/22, 15:06 - Martin: It's a monsters!
42+
9/15/22, 15:07 - Martin: Monstera* (auto correct...)
43+
9/15/22, 15:07 - Philipp: I’m currently running an experiment of keeping my Monstera on the balcony
44+
9/15/22, 15:07 - Martin: A monstera and a fluffy little monster
45+
9/15/22, 15:07 - Philipp: Haha, yeah, hard to tell which is which
46+
9/15/22, 15:07 - Martin: How has it been going with the monstera on the balcony?
47+
9/15/22, 15:08 - Martin: I've tried that too over the summer
48+
9/15/22, 15:08 - Philipp: Pretty bad
49+
9/15/22, 15:08 - Martin: Oh really?
50+
9/15/22, 15:08 - Martin: What happened?
51+
9/15/22, 15:08 - Philipp: Yeah
52+
9/15/22, 15:08 - Philipp: I mean … it’s weird.
53+
9/15/22, 15:08 - Philipp: The leafs that she had are getting dryer and dryer. But she’s also growing plenty of new ones
54+
9/15/22, 15:09 - Philipp: It‘s like she’s changing her summer jacket to a winter jacket
55+
9/15/22, 15:13 - Martin: Yeah something similar happened to ours
56+
9/15/22, 15:14 - Martin: It had thrips over the winter, so we needed to get rid of them
57+
9/15/22, 15:14 - Philipp: Ah, thrips are those tiny little beasts that eat your plants, aren't they?
58+
9/15/22, 15:15 - Martin: Thought that the balcony time would help get rid of them
59+
9/15/22, 15:15 - Martin: Yeah they are horrible, really cute and tiny and deadly
60+
9/15/22, 15:16 - Martin: Most of the monstera's leaves died, but now there are new ones coming
61+
9/15/22, 15:16 - Martin: I think it's the amount of light, they need different leaves for stronger sunlight
62+
9/15/22, 15:17 - Philipp: Do you have any other approaches to get rid of tiny monsters?
63+
9/15/22, 15:17 - Philipp: (Except putting the plant on the balcony)
64+
9/15/22, 15:17 - Martin: Tiny monstera's?
65+
9/15/22, 15:17 - Philipp: Handling tiny monsters to grow big monsteras
66+
9/15/22, 15:17 - Martin: Haha
67+
9/15/22, 15:17 - Martin: Well, no. Just the balcony. This worked best
68+
9/15/22, 15:18 - Martin: We tried applying soapy water
69+
9/15/22, 15:18 - Martin: Which is a suggestion
70+
9/15/22, 15:18 - Martin: And it keeps them a bit in check, but you can't get totally rid of them
71+
9/15/22, 15:18 - Philipp: 10/10 thrips don't like this simple trick 😅
72+
9/15/22, 15:18 - Philipp: Oh, okay
73+
9/15/22, 15:18 - Philipp: 8/10 thrips don't like this simple trick
74+
9/15/22, 15:18 - Martin: I really hope they're gone now 🤞
75+
9/15/22, 15:18 - Martin: Lol
76+
9/15/22, 15:19 - Martin: It's depressing when lil monstera keeps making new leaves for them just to get infected 😢
77+
9/15/22, 15:19 - Philipp: Yeah, nature can be harsh
78+
9/15/22, 15:20 - Martin: Ah yes, it's a slightly strange rendering of nature though, if it's about potted plants
79+
9/15/22, 15:20 - Martin: I feel like they could handle it better out in the wild
80+
9/15/22, 15:21 - Martin: Good that you're making yours strong enough to leave eventually!
81+
9/15/22, 15:22 - Philipp: For the other plants, my words help them to grow
82+
9/15/22, 15:22 - Philipp: Inside and outside
83+
9/15/22, 15:22 - Martin: What are the magic words?
84+
9/15/22, 15:23 - Martin: Wait, do you make *all* plants grow???
85+
9/15/22, 15:24 - Philipp: Grow hastily, grow healthily, grow heartily 🪄✨🌱
86+
9/15/22, 15:24 - Philipp: Do you not make all your plants grow?
87+
9/15/22, 15:24 - Martin: :))
88+
9/15/22, 15:25 - Martin: What do you consider 'your plants'?
89+
9/15/22, 15:28 - Philipp: Oh, now I understand!
90+
9/15/22, 15:29 - Philipp: I only considered the plants that live in my apartment (or my balcony) as the plant-spell-receiving plants
91+
9/15/22, 15:29 - Philipp: But maybe they share the words?
92+
9/15/22, 15:30 - Martin: Do raindrops touch their leaves?
93+
9/15/22, 15:30 - Martin: I'm sure they chat with the other plants if they can
94+
9/15/22, 15:31 - Philipp: Yeah, I heard that trees communicate in the woods with their roots
95+
9/15/22, 15:31 - Philipp: But thinking about that makes me feel bad that my plants are potted 😬
96+
9/15/22, 15:31 - Martin: 😢
97+
9/15/22, 15:32 - Martin: Yeah...
98+
9/15/22, 15:32 - Martin: The trees use mushrooms mycelium in the ground that's hooked to their roots to chat
99+
9/15/22, 15:32 - Martin: Pretty cool 😎
100+
9/15/22, 15:33 - Martin: So i also have a Pilea
101+
9/15/22, 15:33 - Martin: And some basil plants
102+
9/15/22, 15:33 - Philipp: Do you have a photo of the Pilea? I don't know how it looks
103+
9/15/22, 15:34 - Martin: And a peace lily
104+
9/15/22, 15:34 - Martin: https://en.m.wikipedia.org/wiki/Pilea_peperomioides
105+
9/15/22, 15:47 - Philipp: Oh, the Pilea looks cool!
106+
9/15/22, 15:47 - Philipp: The leaves are like small umbrellas
107+
9/15/22, 15:48 - Philipp: Did you actually manage to keep a supermarket basil alive or did you grow it yourself?
108+
9/15/22, 16:28 - Martin: that's quite a story!
109+
9/15/22, 16:28 - Martin: my dad had a flowering basil last year and put the seeds from that one plant into seeding pots
110+
9/15/22, 16:29 - Martin: so many of them came up that he had about two dining room tables full of basil plants, each in their own pots...
111+
9/15/22, 16:29 - Martin: i got three of them, so they are second gen supermarket basils with lots of siblings :)
112+
9/15/22, 20:58 - Philipp: I always thought supermarket basil was meant to die after a few days
113+
9/15/22, 20:58 - Philipp: But it seems it was my subpar care
114+
9/15/22, 20:59 - Philipp: Congratulations to your basil dynasty!
115+
9/16/22, 06:11 - Martin: Thanks!
116+
9/16/22, 06:12 - Martin: Kudos go mostly to my dad
117+
9/16/22, 06:12 - Martin: But you can bring them through winter
118+
9/16/22, 06:12 - Martin: If there's no thrip infestation...
119+
9/16/22, 06:34 - Martin: <Media omitted>
120+
9/16/22, 06:34 - Martin: <Media omitted>
121+
9/16/22, 06:35 - Martin: <Media omitted>
122+
9/16/22, 06:35 - Martin: Morning view of most of my house plants
123+
9/16/22, 09:44 - Philipp: Fingers crossed 🤞
124+
9/16/22, 09:45 - Philipp: Are the ones on top avocados?
125+
9/16/22, 09:53 - Martin: Yes, there are a couple of seedlings that wanted to live
126+
9/16/22, 09:54 - Martin: Two more on the balcony of a similar size
127+
9/16/22, 09:54 - Martin: And another seed that's one it's way 🤷‍♂️
128+
9/16/22, 09:55 - Philipp: I heard that it’s not easy to raise an Avodaco!
129+
9/16/22, 09:55 - Martin: I haven't even heard of Avodacos!
130+
9/16/22, 09:56 - Philipp: Wait, weren’t we talking about avocados?
131+
9/16/22, 09:56 - Martin: Ah yes avocados 🥑!
132+
9/16/22, 09:57 - Martin: I was just joking, riffing based on your typo 😝
133+
9/16/22, 09:57 - Philipp: Ooh! I was wondering why there was a red line under that word
134+
9/16/22, 09:57 - Martin: Do you think there are avotacos? 🥑🌮
135+
9/16/22, 09:57 - Philipp: But I like that term, too
136+
9/16/22, 09:58 - Philipp: 😂
137+
9/16/22, 09:58 - Philipp: If this is not a common term, then I want to make it common!
138+
9/16/22, 09:59 - Martin: Maybe growing an avotaco plant would be a plant symbiosis between an avocado tree and some corn plants?
139+
9/16/22, 10:19 - Philipp: Sounds like the perfect experiment!

0 commit comments

Comments
 (0)