genai14 0.1.0__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 @@
1
+ recursive-include src/genai14/files/Genai *
genai14-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: genai14
3
+ Version: 0.1.0
4
+ Summary: Downloadable collection of beginner Generative AI and machine-learning Python examples
5
+ Author: Genai14 contributors
6
+ License: All rights reserved
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ # genai14
14
+
15
+ A small PyPI package that installs a command-line downloader for the original `Genai` example folder.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ python -m pip install genai14
21
+ ```
22
+
23
+ ## Download the files
24
+
25
+ ```bash
26
+ genai14 download
27
+ ```
28
+
29
+ This creates a `Genai` folder in the current directory. To choose another location:
30
+
31
+ ```bash
32
+ genai14 download ./my-projects
33
+ ```
34
+
35
+ The command will not overwrite an existing `Genai` folder.
36
+
37
+ ## Run a script
38
+
39
+ ```bash
40
+ cd Genai
41
+ python heatwave.py
42
+ ```
43
+
44
+ Some examples need additional libraries:
45
+
46
+ - `bugseverity.py`: `python -m pip install scikit-learn`
47
+ - `pdf.py`: `python -m pip install PyPDF2`
48
+ - `selfattentiontorch.py`, `variatonalencoder.py`, `veon2images.py`: `python -m pip install torch matplotlib`
49
+ - `vector.py`: `python -m pip install scikit-learn`
50
+
51
+ The package installer intentionally does not install heavyweight optional libraries such as PyTorch automatically.
52
+
53
+ ## Included files
54
+
55
+ The original ten Python scripts and `heatwave.pdf` from the supplied archive are included.
@@ -0,0 +1,43 @@
1
+ # genai14
2
+
3
+ A small PyPI package that installs a command-line downloader for the original `Genai` example folder.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ python -m pip install genai14
9
+ ```
10
+
11
+ ## Download the files
12
+
13
+ ```bash
14
+ genai14 download
15
+ ```
16
+
17
+ This creates a `Genai` folder in the current directory. To choose another location:
18
+
19
+ ```bash
20
+ genai14 download ./my-projects
21
+ ```
22
+
23
+ The command will not overwrite an existing `Genai` folder.
24
+
25
+ ## Run a script
26
+
27
+ ```bash
28
+ cd Genai
29
+ python heatwave.py
30
+ ```
31
+
32
+ Some examples need additional libraries:
33
+
34
+ - `bugseverity.py`: `python -m pip install scikit-learn`
35
+ - `pdf.py`: `python -m pip install PyPDF2`
36
+ - `selfattentiontorch.py`, `variatonalencoder.py`, `veon2images.py`: `python -m pip install torch matplotlib`
37
+ - `vector.py`: `python -m pip install scikit-learn`
38
+
39
+ The package installer intentionally does not install heavyweight optional libraries such as PyTorch automatically.
40
+
41
+ ## Included files
42
+
43
+ The original ten Python scripts and `heatwave.pdf` from the supplied archive are included.
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "genai14"
7
+ version = "0.1.0"
8
+ description = "Downloadable collection of beginner Generative AI and machine-learning Python examples"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "All rights reserved" }
12
+ authors = [{ name = "Genai14 contributors" }]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
17
+ ]
18
+
19
+ [project.scripts]
20
+ genai14 = "genai14.cli:main"
21
+
22
+ [tool.setuptools]
23
+ include-package-data = true
24
+
25
+ [tool.setuptools.packages.find]
26
+ where = ["src"]
27
+
28
+ [tool.setuptools.package-data]
29
+ genai14 = ["files/Genai/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ """Downloadable GenAI example files."""
2
+ __version__ = "0.1.0"
@@ -0,0 +1,50 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import shutil
5
+ from importlib.resources import files
6
+ from pathlib import Path
7
+
8
+ from . import __version__
9
+
10
+
11
+ def download(destination: str) -> Path:
12
+ target_parent = Path(destination).expanduser().resolve()
13
+ target = target_parent / "Genai"
14
+ source = files("genai14").joinpath("files", "Genai")
15
+
16
+ target_parent.mkdir(parents=True, exist_ok=True)
17
+ if target.exists():
18
+ raise FileExistsError(
19
+ f"{target} already exists. Choose another destination or rename the existing folder."
20
+ )
21
+
22
+ shutil.copytree(source, target)
23
+ return target
24
+
25
+
26
+ def main() -> None:
27
+ parser = argparse.ArgumentParser(
28
+ prog="genai14",
29
+ description="Download the original Genai example folder to your computer.",
30
+ )
31
+ parser.add_argument("--version", action="version", version=f"genai14 {__version__}")
32
+ subparsers = parser.add_subparsers(dest="command", required=True)
33
+ download_parser = subparsers.add_parser("download", help="Copy the Genai folder to your computer")
34
+ download_parser.add_argument(
35
+ "destination", nargs="?", default=".",
36
+ help="where to create the Genai folder (default: current directory)",
37
+ )
38
+ args = parser.parse_args()
39
+
40
+ if args.command == "download":
41
+ try:
42
+ folder = download(args.destination)
43
+ except FileExistsError as exc:
44
+ parser.error(str(exc))
45
+ print(f"Genai files downloaded to: {folder}")
46
+ print("Open this folder in your editor, or run a script from inside it with Python.")
47
+
48
+
49
+ if __name__ == "__main__":
50
+ main()
@@ -0,0 +1,26 @@
1
+ # Predict Bug Severity using Machine Learning
2
+ from sklearn.tree import DecisionTreeClassifier
3
+
4
+ # Dataset: Temperature, Humidity, Duration, Bug Severity
5
+ X = [
6
+ [30, 40, 2],
7
+ [35, 50, 3],
8
+ [40, 60, 5],
9
+ [45, 70, 6],
10
+ [32, 45, 2],
11
+ [42, 65, 5]
12
+ ]
13
+ y = ["Low", "Low", "Medium", "High", "Low", "High"]
14
+
15
+ # Train model
16
+ model = DecisionTreeClassifier()
17
+ model.fit(X, y)
18
+
19
+ # Accept input
20
+ temp = float(input("Enter Temperature: "))
21
+ humidity = float(input("Enter Humidity: "))
22
+ duration = float(input("Enter Heatwave Duration (days): "))
23
+
24
+ # Predict severity
25
+ result = model.predict([[temp, humidity, duration]])
26
+ print("Predicted Bug Severity:", result[0])
@@ -0,0 +1,8 @@
1
+ temp = [35, 42, 39, 45, 38]
2
+ threshold = 40
3
+
4
+ for t in temp:
5
+ if t > threshold:
6
+ print(t, "- Heatwave Day")
7
+ else:
8
+ print(t, "- Normal Day")
@@ -0,0 +1,45 @@
1
+ qa = {
2
+ "heat": {
3
+ "English": "Irrigate the crop regularly during summer.",
4
+ "Hindi": "Garmi mein fasal ko niyamit paani dein.",
5
+ "Marathi": "Unhalyat pikala niyamit paani dya."
6
+ },
7
+ "water": {
8
+ "English": "Water the crop when soil moisture is low.",
9
+ "Hindi": "Jab mitti sookhi ho tab paani dein.",
10
+ "Marathi": "Mati koradi asel tevha paani dya."
11
+ },
12
+ "rain": {
13
+ "English": "Reduce irrigation during heavy rainfall.",
14
+ "Hindi": "Tez baarish mein paani kam dein.",
15
+ "Marathi": "Jast paus asel tar paani kami dya."
16
+ }
17
+ }
18
+
19
+ print("Select Language:")
20
+ print("1. English")
21
+ print("2. Hindi")
22
+ print("3. Marathi")
23
+
24
+ choice = input("Enter choice: ")
25
+
26
+ lang = {"1": "English", "2": "Hindi", "3": "Marathi"}
27
+
28
+ if choice in lang:
29
+ q = input("Ask your question: ").lower()
30
+
31
+ if any(w in q for w in ["heat", "summer", "garmi", "unhala"]):
32
+ key = "heat"
33
+ elif any(w in q for w in ["water", "paani", "pani"]):
34
+ key = "water"
35
+ elif any(w in q for w in ["rain", "barish", "paus"]):
36
+ key = "rain"
37
+ else:
38
+ key = None
39
+
40
+ if key:
41
+ print("Answer:", qa[key][lang[choice]])
42
+ else:
43
+ print("Answer not available.")
44
+ else:
45
+ print("Invalid choice!")
@@ -0,0 +1,22 @@
1
+ # One-Shot Prompting: Heatwave Monitoring
2
+
3
+ sample_q = "What is a heatwave?"
4
+ sample_a = "A heatwave is a period of extremely high temperature."
5
+
6
+ print("Sample Question:", sample_q)
7
+ print("Sample Answer:", sample_a)
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
+ print("\nGenerated Answer:", answer)
@@ -0,0 +1,28 @@
1
+ import PyPDF2
2
+
3
+ # Load PDF document
4
+ with open("heatwave.pdf", "rb") as file:
5
+ reader = PyPDF2.PdfReader(file)
6
+
7
+ # Extract text from PDF
8
+ text = ""
9
+
10
+ for page in reader.pages:
11
+ text += page.extract_text() or ""
12
+
13
+ # Divide text into chunks
14
+ chunk_size = 200
15
+ chunks = [
16
+ text[i:i + chunk_size]
17
+ for i in range(0, len(text), chunk_size)
18
+ ]
19
+
20
+ print("Extracted Text:")
21
+ print(text)
22
+
23
+ # Display chunks
24
+ print("\nText Chunks:")
25
+
26
+ for i, chunk in enumerate(chunks, start=1):
27
+ print("\nChunk", i)
28
+ print(chunk)
@@ -0,0 +1,17 @@
1
+ import torch
2
+
3
+ tokens = ["soil moisture", "temperature", "rainfall", "irrigation"]
4
+
5
+ x = torch.rand(4, 3)
6
+
7
+ Q = x
8
+ K = x
9
+ V = x
10
+
11
+ scores = Q @ K.T
12
+ attention = torch.softmax(scores, dim=1)
13
+
14
+ output = attention @ V
15
+
16
+ print("Attention Output:")
17
+ print(output)
@@ -0,0 +1,61 @@
1
+ import torch
2
+ import torch.nn as nn
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Generate images locally
6
+ x = torch.rand(50, 784)
7
+
8
+
9
+ # VAE Model
10
+ class VAE(nn.Module):
11
+ def __init__(self):
12
+ super().__init__()
13
+ self.encoder = nn.Linear(784, 128)
14
+ self.mu = nn.Linear(128, 20)
15
+ self.logvar = nn.Linear(128, 20)
16
+ self.decoder = nn.Sequential(
17
+ nn.Linear(20, 128),
18
+ nn.ReLU(),
19
+ nn.Linear(128, 784),
20
+ nn.Sigmoid(),
21
+ )
22
+
23
+ def forward(self, x):
24
+ h = torch.relu(self.encoder(x))
25
+ mu = self.mu(h)
26
+ logvar = self.logvar(h)
27
+
28
+ # Reparameterization
29
+ z = mu + torch.randn_like(mu) * torch.exp(0.5 * logvar)
30
+
31
+ return self.decoder(z), mu, logvar
32
+
33
+ # Create model
34
+ model = VAE()
35
+ optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
36
+
37
+ # Training
38
+ for epoch in range(10):
39
+ output, mu, logvar = model(x)
40
+
41
+ # Reconstruction and KL loss
42
+ loss1 = nn.functional.binary_cross_entropy(
43
+ output, x, reduction="sum"
44
+ )
45
+
46
+ loss2 = -0.5 * torch.sum(
47
+ 1 + logvar - mu.pow(2) - logvar.exp()
48
+ )
49
+
50
+ loss = loss1 + loss2
51
+
52
+ optimizer.zero_grad()
53
+ loss.backward()
54
+ optimizer.step()
55
+
56
+ print("Epoch:", epoch + 1, "Loss:", loss.item())
57
+
58
+ # Display reconstructed image
59
+ plt.imshow(output[0].detach().reshape(28, 28), cmap="gray")
60
+ plt.title("Reconstructed Image")
61
+ plt.show()
@@ -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,51 @@
1
+ import torch
2
+
3
+ import torch.nn as nn
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Generate sample images locally
7
+ x = torch.rand(10, 784)
8
+
9
+ # Encoder and Decoder
10
+ encoder = nn.Linear(784, 2)
11
+ decoder = nn.Sequential(
12
+ nn.Linear(2, 128),
13
+ nn.ReLU(),
14
+ nn.Linear(128, 784),
15
+ nn.Sigmoid(),
16
+ )
17
+
18
+ # Train simple VAE-like model
19
+ opt = torch.optim.Adam(
20
+ list(encoder.parameters()) + list(decoder.parameters()),
21
+ lr=0.01,
22
+ )
23
+
24
+ for epoch in range(50):
25
+ z = encoder(x)
26
+ output = decoder(z)
27
+ loss = nn.functional.mse_loss(output, x)
28
+
29
+ opt.zero_grad()
30
+ loss.backward()
31
+ opt.step()
32
+
33
+ # Display original and reconstructed images
34
+ plt.subplot(1, 2, 1)
35
+ plt.imshow(x[0].reshape(28, 28), cmap="gray")
36
+ plt.title("Original")
37
+
38
+ plt.subplot(1, 2, 2)
39
+ plt.imshow(output[0].detach().reshape(28, 28), cmap="gray")
40
+ plt.title("Reconstructed")
41
+
42
+ # Interpolation between two images
43
+ plt.figure(figsize=(10, 2))
44
+ for i, t in enumerate(torch.linspace(0, 1, 5)):
45
+ z = (1 - t) * encoder(x)[0] + t * encoder(x)[1]
46
+ img = decoder(z).detach().reshape(28, 28)
47
+ plt.subplot(1, 5, i + 1)
48
+ plt.imshow(img, cmap="gray")
49
+ plt.axis("off")
50
+
51
+ plt.show()
@@ -0,0 +1,38 @@
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
+ try:
24
+ ph = float(input("Enter pH value: "))
25
+ except ValueError:
26
+ print("Please enter a valid numeric pH value.")
27
+ else:
28
+ if ph < 7:
29
+ print("Result: Acidic urine.")
30
+ elif ph == 7:
31
+ print("Result: Neutral urine.")
32
+ else:
33
+ print("Result: Alkaline urine.")
34
+
35
+ else:
36
+ print("Test information not available.")
37
+
38
+ print("Interpretation completed.")
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: genai14
3
+ Version: 0.1.0
4
+ Summary: Downloadable collection of beginner Generative AI and machine-learning Python examples
5
+ Author: Genai14 contributors
6
+ License: All rights reserved
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ # genai14
14
+
15
+ A small PyPI package that installs a command-line downloader for the original `Genai` example folder.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ python -m pip install genai14
21
+ ```
22
+
23
+ ## Download the files
24
+
25
+ ```bash
26
+ genai14 download
27
+ ```
28
+
29
+ This creates a `Genai` folder in the current directory. To choose another location:
30
+
31
+ ```bash
32
+ genai14 download ./my-projects
33
+ ```
34
+
35
+ The command will not overwrite an existing `Genai` folder.
36
+
37
+ ## Run a script
38
+
39
+ ```bash
40
+ cd Genai
41
+ python heatwave.py
42
+ ```
43
+
44
+ Some examples need additional libraries:
45
+
46
+ - `bugseverity.py`: `python -m pip install scikit-learn`
47
+ - `pdf.py`: `python -m pip install PyPDF2`
48
+ - `selfattentiontorch.py`, `variatonalencoder.py`, `veon2images.py`: `python -m pip install torch matplotlib`
49
+ - `vector.py`: `python -m pip install scikit-learn`
50
+
51
+ The package installer intentionally does not install heavyweight optional libraries such as PyTorch automatically.
52
+
53
+ ## Included files
54
+
55
+ The original ten Python scripts and `heatwave.pdf` from the supplied archive are included.
@@ -0,0 +1,21 @@
1
+ MANIFEST.in
2
+ README.md
3
+ pyproject.toml
4
+ src/genai14/__init__.py
5
+ src/genai14/cli.py
6
+ src/genai14.egg-info/PKG-INFO
7
+ src/genai14.egg-info/SOURCES.txt
8
+ src/genai14.egg-info/dependency_links.txt
9
+ src/genai14.egg-info/entry_points.txt
10
+ src/genai14.egg-info/top_level.txt
11
+ src/genai14/files/Genai/bugseverity.py
12
+ src/genai14/files/Genai/heatwave.pdf
13
+ src/genai14/files/Genai/heatwave.py
14
+ src/genai14/files/Genai/multilanguage.py
15
+ src/genai14/files/Genai/oneshot.py
16
+ src/genai14/files/Genai/pdf.py
17
+ src/genai14/files/Genai/selfattentiontorch.py
18
+ src/genai14/files/Genai/variatonalencoder.py
19
+ src/genai14/files/Genai/vector.py
20
+ src/genai14/files/Genai/veon2images.py
21
+ src/genai14/files/Genai/zeroshot.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ genai14 = genai14.cli:main
@@ -0,0 +1 @@
1
+ genai14