kjsitgenai 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,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: kjsitgenai
3
+ Version: 0.1.0
4
+ Summary: A python library with pre-written GENAI codes and examples
5
+ Home-page: https://github.com/kjsit/kjsitgenai
6
+ Author: KJSIT
7
+ Author-email: kjsit@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # kjsitgenai
23
+
24
+ A Python library containing pre-written GENAI codes and examples.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install kjsitgenai
30
+ ```
31
+
32
+ ## Extracting Files
33
+
34
+ To copy the bundled files to a specific directory (like `D:\my_kjsit_files`):
35
+
36
+ ```bash
37
+ kjsitgenai D:\my_kjsit_files
38
+ ```
39
+
40
+ If no directory is specified, files are extracted to the current working directory.
@@ -0,0 +1,19 @@
1
+ # kjsitgenai
2
+
3
+ A Python library containing pre-written GENAI codes and examples.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install kjsitgenai
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
+ kjsitgenai 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,44 @@
1
+ import os
2
+ import sys
3
+ import shutil
4
+ from pathlib import Path
5
+
6
+ def main():
7
+ if len(sys.argv) > 1:
8
+ dest_dir = sys.argv[1]
9
+ else:
10
+ # Default to the current terminal directory
11
+ dest_dir = os.getcwd()
12
+
13
+ # Get the directory where this package is installed
14
+ package_dir = os.path.dirname(os.path.abspath(__file__))
15
+ data_dir = os.path.join(package_dir, "data")
16
+
17
+ if not os.path.exists(data_dir):
18
+ print(f"Error: Could not find the data directory inside the package at {data_dir}")
19
+ sys.exit(1)
20
+
21
+ try:
22
+ # If destination doesn't exist, create it
23
+ if not os.path.exists(dest_dir):
24
+ os.makedirs(dest_dir)
25
+ print(f"Created destination directory: {dest_dir}")
26
+
27
+ print(f"Extracting files to {dest_dir}...")
28
+
29
+ # Copy everything from data_dir to dest_dir
30
+ for item in os.listdir(data_dir):
31
+ s = os.path.join(data_dir, item)
32
+ d = os.path.join(dest_dir, item)
33
+ if os.path.isdir(s):
34
+ shutil.copytree(s, d, dirs_exist_ok=True)
35
+ else:
36
+ shutil.copy2(s, d)
37
+
38
+ print("Success! All files have been extracted.")
39
+ except Exception as e:
40
+ print(f"An error occurred while copying files: {e}")
41
+ sys.exit(1)
42
+
43
+ if __name__ == "__main__":
44
+ 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
+ #Implement a simple self-attention mechanism for sugarcane irrigation advisory text using PyTorch.
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,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: kjsitgenai
3
+ Version: 0.1.0
4
+ Summary: A python library with pre-written GENAI codes and examples
5
+ Home-page: https://github.com/kjsit/kjsitgenai
6
+ Author: KJSIT
7
+ Author-email: kjsit@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # kjsitgenai
23
+
24
+ A Python library containing pre-written GENAI codes and examples.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install kjsitgenai
30
+ ```
31
+
32
+ ## Extracting Files
33
+
34
+ To copy the bundled files to a specific directory (like `D:\my_kjsit_files`):
35
+
36
+ ```bash
37
+ kjsitgenai D:\my_kjsit_files
38
+ ```
39
+
40
+ 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
+ kjsitgenai.egg-info/PKG-INFO
8
+ kjsitgenai.egg-info/SOURCES.txt
9
+ kjsitgenai.egg-info/dependency_links.txt
10
+ kjsitgenai.egg-info/entry_points.txt
11
+ kjsitgenai.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
+ kjsitgenai = 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,29 @@
1
+ import os
2
+ from setuptools import setup, find_packages
3
+
4
+ with open("README.md", "r", encoding="utf-8") as fh:
5
+ long_description = fh.read()
6
+
7
+ setup(
8
+ name="kjsitgenai",
9
+ version="0.1.0",
10
+ author="KJSIT",
11
+ author_email="kjsit@example.com",
12
+ description="A python library with pre-written GENAI codes and examples",
13
+ long_description=long_description,
14
+ long_description_content_type="text/markdown",
15
+ url="https://github.com/kjsit/kjsitgenai",
16
+ packages=find_packages(),
17
+ include_package_data=True,
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ ],
23
+ python_requires=">=3.6",
24
+ entry_points={
25
+ 'console_scripts': [
26
+ 'kjsitgenai=kjsitgenai.cli:main',
27
+ ],
28
+ },
29
+ )