kjsitgenai1 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 kjsitgenai/data *
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: kjsitgenai1
3
+ Version: 0.1.0
4
+ Summary: A python library with pre-written GENAI codes and examples
5
+ Author: Neel Parekh
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ Dynamic: author
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-python
16
+ Dynamic: summary
17
+
18
+ # kjsitgenai1
19
+
20
+ A Python library containing pre-written GENAI codes and examples.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install kjsitgenai1
26
+ ```
27
+
28
+ ## Extracting Files
29
+
30
+ To copy the bundled files to a specific directory (like `D:\my_kjsit_files`):
31
+
32
+ ```bash
33
+ kjsitgenai1 D:\my_kjsit_files
34
+ ```
35
+
36
+ If no directory is specified, files are extracted to the current working directory.
@@ -0,0 +1,19 @@
1
+ # kjsitgenai1
2
+
3
+ A Python library containing pre-written GENAI codes and examples.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install kjsitgenai1
9
+ ```
10
+
11
+ ## Extracting Files
12
+
13
+ To copy the bundled files to a specific directory (like `D:\my_kjsit_files`):
14
+
15
+ ```bash
16
+ kjsitgenai1 D:\my_kjsit_files
17
+ ```
18
+
19
+ If no directory is specified, files are extracted to the current working directory.
@@ -0,0 +1,5 @@
1
+ """
2
+ kjsitgenai package
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,53 @@
1
+ import argparse
2
+ import os
3
+ import shutil
4
+ import sys
5
+
6
+
7
+ def main():
8
+ parser = argparse.ArgumentParser(
9
+ prog="kjsitgenai1",
10
+ description="Extract bundled GENAI example scripts to a target directory.",
11
+ )
12
+ parser.add_argument(
13
+ "dest_dir",
14
+ nargs="?",
15
+ default=os.getcwd(),
16
+ help="Destination directory (defaults to current working directory).",
17
+ )
18
+ args = parser.parse_args()
19
+ dest_dir = args.dest_dir
20
+
21
+ # Get the directory where this package is installed
22
+ package_dir = os.path.dirname(os.path.abspath(__file__))
23
+ data_dir = os.path.join(package_dir, "data")
24
+
25
+ if not os.path.exists(data_dir):
26
+ print(f"Error: Could not find the data directory inside the package at {data_dir}")
27
+ sys.exit(1)
28
+
29
+ try:
30
+ # If destination doesn't exist, create it
31
+ if not os.path.exists(dest_dir):
32
+ os.makedirs(dest_dir)
33
+ print(f"Created destination directory: {dest_dir}")
34
+
35
+ print(f"Extracting files to {dest_dir}...")
36
+
37
+ # Copy everything from data_dir to dest_dir
38
+ for item in os.listdir(data_dir):
39
+ s = os.path.join(data_dir, item)
40
+ d = os.path.join(dest_dir, item)
41
+ if os.path.isdir(s):
42
+ shutil.copytree(s, d, dirs_exist_ok=True)
43
+ else:
44
+ shutil.copy2(s, d)
45
+
46
+ print("Success! All files have been extracted.")
47
+ except Exception as e:
48
+ print(f"An error occurred while copying files: {e}")
49
+ sys.exit(1)
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()
@@ -0,0 +1,14 @@
1
+
2
+ # Program to identify heatwave days
3
+
4
+ temperatures = [32, 38, 42, 35, 40, 45, 30]
5
+
6
+ threshold = 40
7
+
8
+ print("Heatwave Days:")
9
+
10
+ for i in range(len(temperatures)):
11
+ if temperatures[i] >= threshold:
12
+ print("Day", i + 1, ":", temperatures[i], "°C - Heatwave")
13
+ else:
14
+ print("Day", i + 1, ":", temperatures[i], "°C - Normal")
@@ -0,0 +1,60 @@
1
+
2
+ import torch
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
+
12
+ decoder = nn.Sequential(
13
+ nn.Linear(2, 128),
14
+ nn.ReLU(),
15
+ nn.Linear(128, 784),
16
+ nn.Sigmoid()
17
+ )
18
+
19
+ # Train simple VAE-like model
20
+ opt = torch.optim.Adam(
21
+ list(encoder.parameters()) +
22
+ list(decoder.parameters()), lr=0.01
23
+ )
24
+
25
+ for epoch in range(50):
26
+ z = encoder(x)
27
+ output = decoder(z)
28
+
29
+ loss = nn.functional.mse_loss(output, x)
30
+
31
+ opt.zero_grad()
32
+ loss.backward()
33
+ opt.step()
34
+
35
+ print("Training Completed!")
36
+
37
+ # Display original and reconstructed images
38
+ plt.subplot(1, 2, 1)
39
+ plt.imshow(x[0].reshape(28, 28), cmap="gray")
40
+ plt.title("Original")
41
+
42
+ plt.subplot(1, 2, 2)
43
+ plt.imshow(output[0].detach().reshape(28, 28), cmap="gray")
44
+ plt.title("Reconstructed")
45
+
46
+ plt.show()
47
+
48
+ # Interpolation between two images
49
+ plt.figure(figsize=(10, 2))
50
+
51
+ for i, t in enumerate(torch.linspace(0, 1, 5)):
52
+ z = (1-t)*encoder(x)[0] + t*encoder(x)[1]
53
+
54
+ img = decoder(z).detach().reshape(28, 28)
55
+
56
+ plt.subplot(1, 5, i+1)
57
+ plt.imshow(img, cmap="gray")
58
+ plt.axis("off")
59
+
60
+ plt.show()
@@ -0,0 +1,34 @@
1
+
2
+ import torch
3
+
4
+ # Sample tokens
5
+ tokens = ["Soil", "Temperature", "Rainfall", "Irrigation"]
6
+
7
+ # Create sample input values
8
+ x = torch.tensor([
9
+ [1.0, 0.0],
10
+ [0.0, 1.0],
11
+ [1.0, 1.0],
12
+ [0.5, 0.5]
13
+ ])
14
+
15
+ # Create Query, Key and Value
16
+ Q = x
17
+ K = x
18
+ V = x
19
+
20
+ # Calculate attention scores
21
+ scores = torch.matmul(Q, K.T)
22
+
23
+ # Apply softmax
24
+ attention = torch.softmax(scores, dim=1)
25
+
26
+ # Calculate final output
27
+ output = torch.matmul(attention, V)
28
+
29
+ print("Tokens:", tokens)
30
+ print("\nAttention Weights:")
31
+ print(attention)
32
+
33
+ print("\nSelf Attention Output:")
34
+ print(output)
@@ -0,0 +1,47 @@
1
+
2
+ # Offline Multilingual QA System for Sugarcane Irrigation
3
+
4
+ # Predefined knowledge base
5
+ answers = {
6
+ "water": [
7
+ "Sugarcane needs sufficient water for growth.",
8
+ "गन्ने को वृद्धि के लिए पर्याप्त पानी चाहिए।",
9
+ "उसाच्या वाढीसाठी पुरेसे पाणी आवश्यक आहे।"
10
+ ],
11
+
12
+ "drip": [
13
+ "Drip irrigation saves water.",
14
+ "ड्रिप सिंचाई से पानी बचता है।",
15
+ "ठिबक सिंचनामुळे पाण्याची बचत होते।"
16
+ ],
17
+
18
+ "stages": [
19
+ "Irrigation is important during germination and growth.",
20
+ "अंकुरण और वृद्धि के समय सिंचाई जरूरी है।",
21
+ "उगवण आणि वाढीच्या काळात सिंचन महत्त्वाचे आहे।"
22
+ ]
23
+ }
24
+
25
+ print("SUGARCANE IRRIGATION QA SYSTEM")
26
+ print("1. English 2. Hindi 3. Marathi")
27
+
28
+ choice = int(input("Select language: "))
29
+
30
+ question = input("Enter your question: ").lower()
31
+
32
+ if "water" in question or "पानी" in question or "पाणी" in question:
33
+ key = "water"
34
+
35
+ elif "drip" in question or "ड्रिप" in question or "ठिबक" in question:
36
+ key = "drip"
37
+
38
+ elif "stage" in question or "अंकुरण" in question or "उगवण" in question:
39
+ key = "stages"
40
+
41
+ else:
42
+ key = None
43
+
44
+ if key:
45
+ print("Answer:", answers[key][choice-1])
46
+ else:
47
+ print("Answer not found in knowledge base.")
@@ -0,0 +1,38 @@
1
+
2
+ # Zero-Shot Prompting - Urine Test Strip Reader
3
+
4
+ print("URINE TEST STRIP READER")
5
+ print("Available Tests: Glucose, Protein, pH")
6
+
7
+ question = input("Ask a question about urine test results: ").lower()
8
+
9
+ if "glucose" in question:
10
+ color = input("Enter strip color: ").lower()
11
+
12
+ if color == "green":
13
+ print("Result: Glucose may be present.")
14
+ else:
15
+ print("Result: Glucose may be absent.")
16
+
17
+ elif "protein" in question:
18
+ color = input("Enter strip color: ").lower()
19
+
20
+ if color in ["green", "blue"]:
21
+ print("Result: Protein may be present.")
22
+ else:
23
+ print("Result: Protein may be absent.")
24
+
25
+ elif "ph" in question:
26
+ ph = float(input("Enter pH value: "))
27
+
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,30 @@
1
+
2
+ # One-Shot Prompting: Heatwave Monitoring
3
+
4
+ # One sample question and answer
5
+ sample_q = "What is a heatwave?"
6
+ sample_a = "A heatwave is a period of extremely high temperature."
7
+
8
+ print("Sample Question:", sample_q)
9
+ print("Sample Answer:", sample_a)
10
+
11
+ # Accept a new question
12
+ question = input("\nAsk a question about heatwaves: ").lower()
13
+
14
+ # Generate answer using predefined knowledge
15
+ if "temperature" in question:
16
+ answer = "High temperature indicates possible heatwave conditions."
17
+
18
+ elif "prediction" in question:
19
+ answer = "Heatwaves can be predicted using temperature forecasts."
20
+
21
+ elif "warning" in question:
22
+ answer = "Issue an early warning and advise people to stay indoors."
23
+
24
+ elif "monitoring" in question:
25
+ answer = "Monitor temperature regularly using weather sensors."
26
+
27
+ else:
28
+ answer = "Stay hydrated and avoid direct sunlight during extreme heat."
29
+
30
+ print("\nGenerated Answer:", answer)
@@ -0,0 +1,28 @@
1
+
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
+
14
+ y = ["Low", "Low", "Medium", "High", "Low", "High"]
15
+
16
+ # Train model
17
+ model = DecisionTreeClassifier()
18
+ model.fit(X, y)
19
+
20
+ # Accept input
21
+ temp = float(input("Enter Temperature: "))
22
+ humidity = float(input("Enter Humidity: "))
23
+ duration = float(input("Enter Heatwave Duration (days): "))
24
+
25
+ # Predict severity
26
+ result = model.predict([[temp, humidity, duration]])
27
+
28
+ print("Predicted Bug Severity:", result[0])
@@ -0,0 +1,32 @@
1
+
2
+ import PyPDF2
3
+
4
+ # Load PDF document
5
+ file = open("heatwave.pdf", "rb")
6
+ reader = PyPDF2.PdfReader(file)
7
+
8
+ # Extract text from PDF
9
+ text = ""
10
+
11
+ for page in reader.pages:
12
+ text += page.extract_text() or ""
13
+
14
+ print("Extracted Text:")
15
+ print(text)
16
+
17
+ # Divide text into chunks
18
+ chunk_size = 200
19
+
20
+ chunks = [
21
+ text[i:i+chunk_size]
22
+ for i in range(0, len(text), chunk_size)
23
+ ]
24
+
25
+ # Display chunks
26
+ print("\nText Chunks:")
27
+
28
+ for i, chunk in enumerate(chunks):
29
+ print("\nChunk", i+1)
30
+ print(chunk)
31
+
32
+ file.close()
@@ -0,0 +1,27 @@
1
+
2
+ from sklearn.feature_extraction.text import TfidfVectorizer
3
+ from sklearn.metrics.pairwise import cosine_similarity
4
+
5
+ # Heatwave data
6
+ data = [
7
+ "Heatwaves cause high temperatures",
8
+ "Drink water to prevent dehydration",
9
+ "Heatwaves cause heatstroke",
10
+ "Weather monitoring predicts heatwaves"
11
+ ]
12
+
13
+ # Generate embeddings
14
+ model = TfidfVectorizer()
15
+ vectors = model.fit_transform(data)
16
+
17
+ # User query
18
+ query = input("Enter query: ")
19
+
20
+ # Calculate similarity
21
+ q = model.transform([query])
22
+ score = cosine_similarity(q, vectors)
23
+
24
+ # Display best matching text
25
+ index = score.argmax()
26
+
27
+ print("Retrieved Text:", data[index])
@@ -0,0 +1,65 @@
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Generate images locally
7
+ x = torch.rand(50, 784)
8
+
9
+ # VAE Model
10
+ class VAE(nn.Module):
11
+ def __init__(self):
12
+ super().__init__()
13
+
14
+ self.encoder = nn.Linear(784, 128)
15
+ self.mu = nn.Linear(128, 20)
16
+ self.logvar = nn.Linear(128, 20)
17
+
18
+ self.decoder = nn.Sequential(
19
+ nn.Linear(20, 128),
20
+ nn.ReLU(),
21
+ nn.Linear(128, 784),
22
+ nn.Sigmoid()
23
+ )
24
+
25
+ def forward(self, x):
26
+ h = torch.relu(self.encoder(x))
27
+
28
+ mu = self.mu(h)
29
+ logvar = self.logvar(h)
30
+
31
+ # Reparameterization
32
+ z = mu + torch.randn_like(mu) * torch.exp(0.5 * logvar)
33
+
34
+ return self.decoder(z), mu, logvar
35
+
36
+
37
+ # Create model
38
+ model = VAE()
39
+ optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
40
+
41
+ # Training
42
+ for epoch in range(10):
43
+ output, mu, logvar = model(x)
44
+
45
+ # Reconstruction and KL loss
46
+ loss1 = nn.functional.binary_cross_entropy(
47
+ output, x, reduction='sum'
48
+ )
49
+
50
+ loss2 = -0.5 * torch.sum(
51
+ 1 + logvar - mu.pow(2) - logvar.exp()
52
+ )
53
+
54
+ loss = loss1 + loss2
55
+
56
+ optimizer.zero_grad()
57
+ loss.backward()
58
+ optimizer.step()
59
+
60
+ print("Epoch:", epoch+1, "Loss:", loss.item())
61
+
62
+ # Display reconstructed image
63
+ plt.imshow(output[0].detach().reshape(28, 28), cmap='gray')
64
+ plt.title("Reconstructed Image")
65
+ plt.show()
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: kjsitgenai1
3
+ Version: 0.1.0
4
+ Summary: A python library with pre-written GENAI codes and examples
5
+ Author: Neel Parekh
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ Dynamic: author
12
+ Dynamic: classifier
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: requires-python
16
+ Dynamic: summary
17
+
18
+ # kjsitgenai1
19
+
20
+ A Python library containing pre-written GENAI codes and examples.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install kjsitgenai1
26
+ ```
27
+
28
+ ## Extracting Files
29
+
30
+ To copy the bundled files to a specific directory (like `D:\my_kjsit_files`):
31
+
32
+ ```bash
33
+ kjsitgenai1 D:\my_kjsit_files
34
+ ```
35
+
36
+ If no directory is specified, files are extracted to the current working directory.
@@ -0,0 +1,21 @@
1
+ MANIFEST.in
2
+ README.md
3
+ setup.py
4
+ kjsitgenai/__init__.py
5
+ kjsitgenai/__main__.py
6
+ kjsitgenai/cli.py
7
+ kjsitgenai1.egg-info/PKG-INFO
8
+ kjsitgenai1.egg-info/SOURCES.txt
9
+ kjsitgenai1.egg-info/dependency_links.txt
10
+ kjsitgenai1.egg-info/entry_points.txt
11
+ kjsitgenai1.egg-info/top_level.txt
12
+ kjsitgenai/data/exp1.py
13
+ kjsitgenai/data/exp10.py
14
+ kjsitgenai/data/exp2.py
15
+ kjsitgenai/data/exp3multilingual.py
16
+ kjsitgenai/data/exp4_zero_shot.py
17
+ kjsitgenai/data/exp5.py
18
+ kjsitgenai/data/exp6.py
19
+ kjsitgenai/data/exp7.py
20
+ kjsitgenai/data/exp8.py
21
+ kjsitgenai/data/exp9.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kjsitgenai1 = kjsitgenai.cli:main
@@ -0,0 +1 @@
1
+ kjsitgenai
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,27 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="kjsitgenai1",
8
+ version="0.1.0",
9
+ author="Neel Parekh",
10
+ description="A python library with pre-written GENAI codes and examples",
11
+ long_description=long_description,
12
+ long_description_content_type="text/markdown",
13
+ packages=find_packages(),
14
+ package_data={"kjsitgenai": ["data/*"]},
15
+ include_package_data=True,
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ],
21
+ python_requires=">=3.8",
22
+ entry_points={
23
+ "console_scripts": [
24
+ "kjsitgenai1=kjsitgenai.cli:main",
25
+ ],
26
+ },
27
+ )