pycodevault 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ recursive-include src/pycodevault/library *.py
2
+ recursive-include src/pycodevault/library *.pdf
3
+ recursive-include src/pycodevault/library *.md
4
+ recursive-include src/pycodevault/library *.txt
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycodevault
3
+ Version: 1.0.1
4
+ Summary: A collection of Python programs, AI/ML implementations, NLP models and development projects.
5
+ Author: PyCodeVault
6
+ License: MIT
7
+ Keywords: python,python-programs,source-code,data-structures,algorithms,leetcode,machine-learning,deep-learning,artificial-intelligence,natural-language-processing,generative-ai,transformers,bert,rag,vector-embeddings,neural-networks,computer-science
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Software Development
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/plain
14
+
15
+ PyCodeVault - Python Source Code Collection
@@ -0,0 +1,61 @@
1
+
2
+ [build-system]
3
+ requires = ["setuptools>=68", "wheel"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "pycodevault"
8
+ version = "1.0.1"
9
+ description = "A collection of Python programs, AI/ML implementations, NLP models and development projects."
10
+ readme = {text = "PyCodeVault - Python Source Code Collection", content-type = "text/plain"}
11
+ requires-python = ">=3.9"
12
+ license = {text = "MIT"}
13
+
14
+ authors = [
15
+ {name = "PyCodeVault"}
16
+ ]
17
+
18
+ keywords = [
19
+ "python",
20
+ "python-programs",
21
+ "source-code",
22
+ "data-structures",
23
+ "algorithms",
24
+ "leetcode",
25
+ "machine-learning",
26
+ "deep-learning",
27
+ "artificial-intelligence",
28
+ "natural-language-processing",
29
+ "generative-ai",
30
+ "transformers",
31
+ "bert",
32
+ "rag",
33
+ "vector-embeddings",
34
+ "neural-networks",
35
+ "computer-science"
36
+ ]
37
+
38
+ classifiers = [
39
+ "Programming Language :: Python :: 3",
40
+ "Operating System :: OS Independent",
41
+ "Topic :: Software Development",
42
+ "Topic :: Scientific/Engineering :: Artificial Intelligence"
43
+ ]
44
+
45
+ [project.scripts]
46
+ pycodevault = "pycodevault.downloader:main"
47
+
48
+ [tool.setuptools]
49
+ package-dir = {"" = "src"}
50
+ include-package-data = true
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+ include = ["pycodevault", "pycodevault.*"]
55
+
56
+ [tool.setuptools.package-data]
57
+ pycodevault = [
58
+ "library/**/*",
59
+ "library/**/**/*",
60
+ "library/**/**/**/*"
61
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ __version__ = "1.0.1"
@@ -0,0 +1,72 @@
1
+
2
+ import argparse
3
+ import shutil
4
+ import sys
5
+ from pathlib import Path
6
+
7
+
8
+ def download_library(destination=None):
9
+
10
+ source = Path(__file__).resolve().parent / "library"
11
+
12
+ target = (
13
+ Path(destination).expanduser().resolve()
14
+ if destination
15
+ else Path.cwd() / "PyCodeVault"
16
+ )
17
+
18
+ if not source.is_dir():
19
+ print("Error: PyCodeVault library files were not found.")
20
+ return 1
21
+
22
+ if target.exists():
23
+ print(f"Destination already exists: {target}")
24
+ print("Please choose another destination.")
25
+ return 1
26
+
27
+ try:
28
+ shutil.copytree(source, target)
29
+
30
+ print("\nPyCodeVault downloaded successfully!")
31
+ print(f"Files saved at: {target}")
32
+ print("\nYou can now access your Python files offline.")
33
+
34
+ return 0
35
+
36
+ except PermissionError:
37
+ print("Error: Permission denied. Choose another location.")
38
+ return 1
39
+
40
+ except OSError as error:
41
+ print(f"Error while downloading library: {error}")
42
+ return 1
43
+
44
+
45
+ def main():
46
+
47
+ parser = argparse.ArgumentParser(
48
+ description="Download the PyCodeVault Python source collection."
49
+ )
50
+
51
+ subparsers = parser.add_subparsers(dest="command")
52
+
53
+ download_parser = subparsers.add_parser(
54
+ "download",
55
+ help="Download the complete Python code collection."
56
+ )
57
+
58
+ download_parser.add_argument(
59
+ "--path",
60
+ help="Optional destination directory."
61
+ )
62
+
63
+ args = parser.parse_args()
64
+
65
+ if args.command == "download":
66
+ sys.exit(download_library(args.path))
67
+
68
+ parser.print_help()
69
+
70
+
71
+ if __name__ == "__main__":
72
+ main()
@@ -0,0 +1,32 @@
1
+ from sklearn.tree import DecisionTreeClassifier
2
+
3
+
4
+ X = [
5
+ [30, 40, 2],
6
+ [35, 50, 3],
7
+ [40, 60, 5],
8
+ [45, 70, 6],
9
+ [32, 45, 2],
10
+ [42, 65, 5]
11
+ ]
12
+
13
+
14
+ y = ["Low", "Low", "Medium", "High", "Low", "High"]
15
+
16
+
17
+
18
+ model = DecisionTreeClassifier()
19
+ model.fit(X, y)
20
+
21
+
22
+
23
+ temp = float(input("Enter Temperature: "))
24
+ humidity = float(input("Enter Humidity: "))
25
+ duration = float(input("Enter Heatwave Duration (days): "))
26
+
27
+
28
+
29
+ result = model.predict([[temp, humidity, duration]])
30
+
31
+
32
+ print("Predicted Bug Severity:", result[0])
@@ -0,0 +1,23 @@
1
+ sample_q = "What is a heatwave?"
2
+ sample_a = "A heatwave is a period of extremely high temperature."
3
+
4
+
5
+ print("Sample Question:", sample_q)
6
+ print("Sample Answer:", sample_a)
7
+
8
+
9
+ question = input("\nAsk a question about heatwaves: ").lower()
10
+
11
+ if "temperature" in question:
12
+ answer = "High temperature indicates possible heatwave conditions."
13
+ elif "prediction" in question:
14
+ answer = "Heatwaves can be predicted using temperature forecasts."
15
+ elif "warning" in question:
16
+ answer = "Issue an early warning and advise people to stay indoors."
17
+ elif "monitoring" in question:
18
+ answer = "Monitor temperature regularly using weather sensors."
19
+ else:
20
+ answer = "Stay hydrated and avoid direct sunlight during extreme heat."
21
+
22
+
23
+ print("\nGenerated Answer:", answer)
@@ -0,0 +1,40 @@
1
+ answers = {
2
+ "water": [
3
+ "Sugarcane needs sufficient water for growth.",
4
+ "गन्ने को वृद्धि के लिए पर्याप्त पानी चाहिए।",
5
+ "उसाच्या वाढीसाठी पुरेसे पाणी आवश्यक आहे।"
6
+ ],
7
+
8
+ "drip": [
9
+ "Drip irrigation saves water.",
10
+ "ड्रिप सिंचाई से पानी बचता है।",
11
+ "ठिबक सिंचनामुळे पाण्याची बचत होते।"
12
+ ],
13
+
14
+ "stages": [
15
+ "Irrigation is important during germination and growth.",
16
+ "अंकुरण और वृद्धि के समय सिंचाई जरूरी है।",
17
+ "उगवण आणि वाढीच्या काळात सिंचन महत्त्वाचे आहे।"
18
+ ]
19
+ }
20
+
21
+ print("SUGARCANE IRRIGATION QA SYSTEM")
22
+ print("1. English 2. Hindi 3. Marathi")
23
+
24
+ choice = int(input("Select language: "))
25
+
26
+ question = input("Enter your question: ").lower()
27
+
28
+ if "water" in question or "पानी" in question or "पाणी" in question:
29
+ key = "water"
30
+ elif "drip" in question or "ड्रिप" in question or "ठिबक" in question:
31
+ key = "drip"
32
+ elif "stage" in question or "अंकुरण" in question or "उगवण" in question:
33
+ key = "stages"
34
+ else:
35
+ key = None
36
+
37
+ if key:
38
+ print("Answer:", answers[key][choice-1])
39
+ else:
40
+ print("Answer not found in knowledge base.")
@@ -0,0 +1,119 @@
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ import matplotlib.pyplot as plt
5
+ from torchvision import datasets, transforms
6
+ from torch.utils.data import DataLoader
7
+
8
+ # 1. Load real MNIST images
9
+ transform = transforms.ToTensor()
10
+
11
+ dataset = datasets.MNIST(
12
+ root="./data",
13
+ train=True,
14
+ download=True,
15
+ transform=transform
16
+ )
17
+
18
+ loader = DataLoader(dataset, batch_size=128, shuffle=True)
19
+
20
+
21
+ # 2. Create VAE model
22
+ class VAE(nn.Module):
23
+
24
+ def __init__(self):
25
+ super().__init__()
26
+
27
+ self.encoder = nn.Sequential(
28
+ nn.Linear(784, 256),
29
+ nn.ReLU()
30
+ )
31
+
32
+ self.mu = nn.Linear(256, 20)
33
+ self.logvar = nn.Linear(256, 20)
34
+
35
+ self.decoder = nn.Sequential(
36
+ nn.Linear(20, 256),
37
+ nn.ReLU(),
38
+ nn.Linear(256, 784),
39
+ nn.Sigmoid()
40
+ )
41
+
42
+ def forward(self, x):
43
+
44
+ h = self.encoder(x)
45
+
46
+ mu = self.mu(h)
47
+ logvar = self.logvar(h)
48
+
49
+ # Reparameterization
50
+ z = mu + torch.randn_like(mu) * torch.exp(0.5 * logvar)
51
+
52
+ output = self.decoder(z)
53
+
54
+ return output, mu, logvar
55
+
56
+
57
+ # 3. Initialize model
58
+ model = VAE()
59
+
60
+ optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
61
+
62
+
63
+ # 4. Train the VAE
64
+ for epoch in range(5):
65
+
66
+ total_loss = 0
67
+
68
+ for images, labels in loader:
69
+
70
+ images = images.view(-1, 784)
71
+
72
+ output, mu, logvar = model(images)
73
+
74
+ # Reconstruction loss
75
+ reconstruction_loss = nn.functional.binary_cross_entropy(
76
+ output, images, reduction="sum"
77
+ )
78
+
79
+ # KL divergence loss
80
+ kl_loss = -0.5 * torch.sum(
81
+ 1 + logvar - mu.pow(2) - logvar.exp()
82
+ )
83
+
84
+ loss = reconstruction_loss + kl_loss
85
+
86
+ optimizer.zero_grad()
87
+ loss.backward()
88
+ optimizer.step()
89
+
90
+ total_loss += loss.item()
91
+
92
+ print("Epoch:", epoch + 1, "Loss:", total_loss / len(dataset))
93
+
94
+
95
+ # 5. Display original and reconstructed images
96
+ images, labels = next(iter(loader))
97
+
98
+ with torch.no_grad():
99
+ output, _, _ = model(images.view(-1, 784))
100
+
101
+ plt.figure(figsize=(10, 4))
102
+
103
+ for i in range(8):
104
+
105
+ # Original image
106
+ plt.subplot(2, 8, i + 1)
107
+ plt.imshow(images[i].squeeze(), cmap="gray")
108
+ plt.axis("off")
109
+ plt.title("Original")
110
+
111
+ # Reconstructed image
112
+ plt.subplot(2, 8, i + 9)
113
+ plt.imshow(output[i].reshape(28, 28), cmap="gray")
114
+ plt.axis("off")
115
+ plt.title("Reconstructed")
116
+
117
+ plt.tight_layout()
118
+ plt.show()
119
+
@@ -0,0 +1,182 @@
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ import matplotlib.pyplot as plt
5
+ from torchvision import datasets, transforms
6
+ from torch.utils.data import DataLoader
7
+
8
+ # 1. Load MNIST dataset
9
+ dataset = datasets.MNIST(
10
+ root="./data",
11
+ train=True,
12
+ download=True,
13
+ transform=transforms.ToTensor()
14
+ )
15
+
16
+ # Use 5000 real images
17
+ images = torch.stack([dataset[i][0] for i in range(5000)])
18
+ labels = torch.tensor([dataset[i][1] for i in range(5000)])
19
+
20
+ loader = DataLoader(
21
+ list(zip(images, labels)),
22
+ batch_size=128,
23
+ shuffle=True
24
+ )
25
+
26
+
27
+ # 2. Create VAE
28
+ class VAE(nn.Module):
29
+
30
+ def __init__(self):
31
+ super().__init__()
32
+
33
+ self.encoder = nn.Sequential(
34
+ nn.Linear(784, 256),
35
+ nn.ReLU(),
36
+ nn.Linear(256, 128),
37
+ nn.ReLU()
38
+ )
39
+
40
+ self.mu = nn.Linear(128, 20)
41
+ self.logvar = nn.Linear(128, 20)
42
+
43
+ self.decoder = nn.Sequential(
44
+ nn.Linear(20, 128),
45
+ nn.ReLU(),
46
+ nn.Linear(128, 256),
47
+ nn.ReLU(),
48
+ nn.Linear(256, 784),
49
+ nn.Sigmoid()
50
+ )
51
+
52
+ def forward(self, x):
53
+
54
+ h = self.encoder(x)
55
+
56
+ mu = self.mu(h)
57
+ logvar = self.logvar(h)
58
+
59
+ # Reparameterization
60
+ z = mu + torch.randn_like(mu) * torch.exp(0.5 * logvar)
61
+
62
+ output = self.decoder(z)
63
+
64
+ return output, mu, logvar
65
+
66
+
67
+ # 3. Train model
68
+ model = VAE()
69
+ optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
70
+
71
+ for epoch in range(25):
72
+
73
+ total_loss = 0
74
+
75
+ for batch, _ in loader:
76
+
77
+ batch = batch.view(-1, 784)
78
+
79
+ output, mu, logvar = model(batch)
80
+
81
+ # Reconstruction loss
82
+ loss1 = nn.functional.binary_cross_entropy(
83
+ output, batch, reduction="sum"
84
+ )
85
+
86
+ # KL divergence loss
87
+ loss2 = -0.5 * torch.sum(
88
+ 1 + logvar - mu.pow(2) - logvar.exp()
89
+ )
90
+
91
+ loss = loss1 + loss2
92
+
93
+ optimizer.zero_grad()
94
+ loss.backward()
95
+ optimizer.step()
96
+
97
+ total_loss += loss.item()
98
+
99
+ print("Epoch:", epoch + 1,
100
+ "Loss:", round(total_loss / len(dataset), 2))
101
+
102
+
103
+ # 4. Reconstruct images
104
+ # Use mean (mu) for stable reconstruction
105
+ model.eval()
106
+
107
+ with torch.no_grad():
108
+
109
+ sample = images[:10].view(-1, 784)
110
+
111
+ h = model.encoder(sample)
112
+ mu = model.mu(h)
113
+
114
+ reconstructed = model.decoder(mu)
115
+
116
+
117
+ plt.figure(figsize=(12, 4))
118
+
119
+ for i in range(10):
120
+
121
+ plt.subplot(2, 10, i + 1)
122
+ plt.imshow(sample[i].reshape(28, 28), cmap="gray")
123
+ plt.title("Original")
124
+ plt.axis("off")
125
+
126
+ plt.subplot(2, 10, i + 11)
127
+ plt.imshow(reconstructed[i].reshape(28, 28), cmap="gray")
128
+ plt.title("Reconstructed")
129
+ plt.axis("off")
130
+
131
+ plt.tight_layout()
132
+ plt.show()
133
+
134
+
135
+ # 5. Visualize latent space
136
+ # Plot first two latent dimensions
137
+
138
+ with torch.no_grad():
139
+
140
+ all_images = images.view(-1, 784)
141
+ h = model.encoder(all_images)
142
+ latent = model.mu(h)
143
+
144
+ plt.figure(figsize=(8, 6))
145
+
146
+ scatter = plt.scatter(
147
+ latent[:, 0],
148
+ latent[:, 1],
149
+ c=labels.numpy(),
150
+ cmap="tab10",
151
+ s=8
152
+ )
153
+
154
+ plt.colorbar(scatter, label="Digit")
155
+ plt.xlabel("Latent Dimension 1")
156
+ plt.ylabel("Latent Dimension 2")
157
+ plt.title("VAE Latent Space Visualization")
158
+ plt.show()
159
+
160
+
161
+ # 6. Interpolation between two images
162
+
163
+ with torch.no_grad():
164
+
165
+ # Select two images
166
+ z1 = mu[0]
167
+ z2 = mu[1]
168
+
169
+ plt.figure(figsize=(12, 2))
170
+
171
+ for i, t in enumerate(torch.linspace(0, 1, 8)):
172
+
173
+ z = (1 - t) * z1 + t * z2
174
+
175
+ img = model.decoder(z)
176
+
177
+ plt.subplot(1, 8, i + 1)
178
+ plt.imshow(img.reshape(28, 28), cmap="gray")
179
+ plt.axis("off")
180
+
181
+ plt.suptitle("Smooth Image Interpolation")
182
+ plt.show()
@@ -0,0 +1,35 @@
1
+ print("URINE TEST STRIP READER")
2
+ print("Available Tests: Glucose, Protein, pH")
3
+
4
+ question = input("Ask a question about urine test results: ").lower()
5
+
6
+ if "glucose" in question:
7
+ color = input("Enter strip color: ").lower()
8
+
9
+ if color == "green":
10
+ print("Result: Glucose may be present.")
11
+ else:
12
+ print("Result: Glucose may be absent.")
13
+
14
+ elif "protein" in question:
15
+ color = input("Enter strip color: ").lower()
16
+
17
+ if color in ["green", "blue"]:
18
+ print("Result: Protein may be present.")
19
+ else:
20
+ print("Result: Protein may be absent.")
21
+
22
+ elif "ph" in question:
23
+ ph = float(input("Enter pH value: "))
24
+
25
+ if ph < 7:
26
+ print("Result: Acidic urine.")
27
+ elif ph == 7:
28
+ print("Result: Neutral urine.")
29
+ else:
30
+ print("Result: Alkaline urine.")
31
+
32
+ else:
33
+ print("Test information not available.")
34
+
35
+ print("Interpretation completed.")
@@ -0,0 +1,13 @@
1
+ temperatures = [32, 35, 38, 42, 40, 36, 43]
2
+
3
+ threshold = 40
4
+
5
+ print("Heatwave Days:")
6
+
7
+ for i in range(len(temperatures)):
8
+
9
+ if temperatures[i] >= threshold:
10
+ print("Day", i + 1, ":", temperatures[i], "°C - Heatwave")
11
+ else:
12
+ print("Day", i + 1, ":", temperatures[i], "°C - Normal")
13
+
@@ -0,0 +1,28 @@
1
+ import PyPDF2
2
+
3
+
4
+ file = open("heatwave.pdf", "rb")
5
+ reader = PyPDF2.PdfReader(file)
6
+
7
+
8
+ text = ""
9
+
10
+ for page in reader.pages:
11
+ text += page.extract_text() or ""
12
+
13
+ print("Extracted Text:")
14
+ print(text)
15
+
16
+ # Divide text into chunks
17
+ chunk_size = 200
18
+ chunks = [text[i:i+chunk_size]
19
+ for i in range(0, len(text), chunk_size)]
20
+
21
+ # Display chunks
22
+ print("\nText Chunks:")
23
+
24
+ for i, chunk in enumerate(chunks):
25
+ print("\nChunk", i+1)
26
+ print(chunk)
27
+
28
+ file.close()
@@ -0,0 +1,32 @@
1
+ import torch
2
+ import torch.nn.functional as F
3
+
4
+ # Sample tokens
5
+ tokens = ["soil_moisture", "temperature", "rainfall", "irrigation"]
6
+
7
+ # Create sample embeddings
8
+ X = torch.rand(4, 4)
9
+
10
+ # Create Query, Key and Value
11
+ Q = X
12
+ K = X
13
+ V = X
14
+
15
+ # Calculate attention scores
16
+ scores = torch.matmul(Q, K.T)
17
+
18
+ # Apply softmax
19
+ attention = F.softmax(scores, dim=1)
20
+
21
+ # Calculate output
22
+ output = torch.matmul(attention, V)
23
+
24
+ # Display results
25
+ print("Input Tokens:")
26
+ print(tokens)
27
+
28
+ print("\nAttention Weights:")
29
+ print(attention)
30
+
31
+ print("\nSelf-Attention Output:")
32
+ print(output)
@@ -0,0 +1,26 @@
1
+ from sklearn.feature_extraction.text import TfidfVectorizer
2
+ from sklearn.metrics.pairwise import cosine_similarity
3
+
4
+ # Heatwave data
5
+ data = [
6
+ "Heatwaves cause high temperatures",
7
+ "Drink water to prevent dehydration",
8
+ "Heatwaves cause heatstroke",
9
+ "Weather monitoring predicts heatwaves"
10
+ ]
11
+
12
+ # Generate embeddings
13
+ model = TfidfVectorizer()
14
+ vectors = model.fit_transform(data)
15
+
16
+ # User query
17
+ query = input("Enter query: ")
18
+
19
+ # Calculate similarity
20
+ q = model.transform([query])
21
+ score = cosine_similarity(q, vectors)
22
+
23
+ # Display best matching text
24
+ index = score.argmax()
25
+
26
+ print("Retrieved Text:", data[index])
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycodevault
3
+ Version: 1.0.1
4
+ Summary: A collection of Python programs, AI/ML implementations, NLP models and development projects.
5
+ Author: PyCodeVault
6
+ License: MIT
7
+ Keywords: python,python-programs,source-code,data-structures,algorithms,leetcode,machine-learning,deep-learning,artificial-intelligence,natural-language-processing,generative-ai,transformers,bert,rag,vector-embeddings,neural-networks,computer-science
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Software Development
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/plain
14
+
15
+ PyCodeVault - Python Source Code Collection
@@ -0,0 +1,20 @@
1
+ MANIFEST.in
2
+ pyproject.toml
3
+ src/pycodevault/__init__.py
4
+ src/pycodevault/downloader.py
5
+ src/pycodevault.egg-info/PKG-INFO
6
+ src/pycodevault.egg-info/SOURCES.txt
7
+ src/pycodevault.egg-info/dependency_links.txt
8
+ src/pycodevault.egg-info/entry_points.txt
9
+ src/pycodevault.egg-info/top_level.txt
10
+ src/pycodevault/library/BugSeverity.py
11
+ src/pycodevault/library/OneShot.py
12
+ src/pycodevault/library/QA.py
13
+ src/pycodevault/library/VAE.py
14
+ src/pycodevault/library/VAEinterpolation.py
15
+ src/pycodevault/library/ZeroShot.py
16
+ src/pycodevault/library/heatwave.pdf
17
+ src/pycodevault/library/heatwavedays.py
18
+ src/pycodevault/library/rag.py
19
+ src/pycodevault/library/selfattention.py
20
+ src/pycodevault/library/vector.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pycodevault = pycodevault.downloader:main
@@ -0,0 +1 @@
1
+ pycodevault