<jupyter_start><jupyter_text>Install necessary libraries%pip install scipy numpy keras tensorflow matplotlib  Train Model<jupyter_code># Import necessary libraries
import os
import numpy as np
import matplotlib.pyplot as plt
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras import backend as K
# Load images
datagen = ImageDataGenerator(rescale=1./255)
train_generator = datagen.flow_from_directory(
        'images/',
        target_size=(252, 252),
        batch_size=2,
        class_mode=None)
# Reshape images
train_images = train_generator.next()
train_images = train_images.reshape((252, 252, 3, -1))
train_images = train_images.transpose(3, 0, 1, 2)
# Create encoder model
input_img = Input(shape=(252, 252, 3))

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)

x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)

# Create decoder model
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(3, (3, 3), activation='sigmoid', padding='same')(x)

# Create autoencoder model
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
autoencoder.summary()
# Train autoencoder
autoencoder.fit(train_images, train_images, epochs=100, batch_size=20,verbose = 0)
# Save encoder model
encoder = Model(input_img, encoded)
encoder.save('encoder.h5')<jupyter_output>WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.<jupyter_text>Use Model<jupyter_code># Import libraries
import os
import numpy as np
import matplotlib.pyplot as plt
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras import backend as K
# Now, for a given image, use the encoder model to produce embeddings
import os
embeddings_list = []
cyclone_names = []

# Load encoder model
from keras.models import load_model
encoder = load_model('encoder.h5')

# Load image
from keras.preprocessing.image import load_img
for file in os.listdir('images/image_dataset/'):
    if ".jpg" in file:
        image = load_img(f'images/image_dataset/{file}', target_size=(252, 252))

        # Reshape image
        image = np.array(image)
        image = image.reshape((252, 252, 3, -1))
        image = image.transpose(3, 0, 1, 2)

        # Produce embedding
        embedding = encoder.predict(image)
        embeddings_list.append(embedding)
        cyclone_names.append(file)

#print(embedding)
# Length of each embedding vector is 32
len(embedding[0])
def cosine_similarity(v1, v2):
    return np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
from IPython.display import Image
# Select appropriate file
print('01b Cyclone')
Image(filename= f"images/image_dataset/01b_2.jpg")
anchor_embedding = embeddings_list[0]
sims = []
for x in embeddings_list:
    sims.append(cosine_similarity(anchor_embedding.flatten(),x.flatten()))
top_k = cyclone_names[:]
new_sims = sims[:]
new_sims.sort(reverse=True)
new_sims[1:6]<jupyter_output><empty_output><jupyter_text>Compare Similarity<jupyter_code>name_list = []
for x in new_sims[1:6]:
    name_list.append(top_k[sims.index(x)])
name_list
from IPython.display import Image
# select cyclone from returned list of similar responses
print(name_list[0].split('.')[0].capitalize() + " Cyclone")
Image(filename= f"images/image_dataset/{name_list[0]}")<jupyter_output>Queensland Cyclone<jupyter_text>Cyclone Search and Compare<jupyter_code>%pip install bs4 wikipedia
import wikipedia
def cyclone_details(cyclone_name):
    summary = wikipedia.summary(cyclone_name, sentences=10)
    search_result = wikipedia.page(cyclone_name)
    title = search_result.title
    content = search_result.content
    link = search_result.url
    
    print(title)
    print(f"Link: {link}\n")
    print("SUMMARY:")
    print(summary)
    print()
    print("Full Content:")
    print(content)
    return content
cyclone_details('01b')
 details = cyclone_details('Queensland Cyclone')
%pip install sentence-transformers
from sentence_transformers import SentenceTransformer, util
embedder =  SentenceTransformer('msmarco-distilbert-base-tas-b')
# Store model for future use
import pickle
with open("sentence_model.pkl","wb") as pickle_file:
    pickle.dump(embedder, pickle_file)
# Load model if saved
with open("sentence_model.pkl","rb") as pickle_file:
    embedder = pickle.load(pickle_file)	
query = input()
query_embedding = embedder.encode(query)
passage = details.split('.')
passage_embeddings = embedder.encode(passage)
hits = util.semantic_search(query_embedding, passage_embeddings, top_k=5)
for hit in hits[0]:
    print(passage[hit['corpus_id']], "(Score: {:.4f})".format(hit['score']))<jupyter_output>What steps were taken against it
{'fraction_non_alphanumeric': 0.12572066207922633, 'fraction_numerical': 0.02603682350753208, 'mean_word_length': 5.655940594059406, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '401623', 'license': 'MIT', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1828, 'n_words': 446, 'path': 'Cyclone.ipynb', 'repo_name': 'Sharan-Babu/CycloneSearch', 'size': '5377'}