import re import numpy as np import tensorflow as tf from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences from sklearn.preprocessing import LabelEncoder # Sample dataset (you should use your own dataset) titles = ["Jitsu wa Ore, Saikyou deshita?", "Mushoku Tensei II: Isekai Ittara Honki Dasu", "Zom 100: Zombie ni Naru made ni Shitai 100 no Koto", "Kanojo, Okarishimasu 3rd Season", "Hataraku Maou-sama!! 2nd Season", "Rurouni Kenshin: Meiji Kenkaku Romantan (2023)"] links = ["https://9anime.homes/stream/play.php?slug=jitsu-wa-ore-saikyou-deshita","https://9anime.homes/stream/play.php?slug=mushoku-tensei-ii-isekai-ittara-honki-dasu", "https://9anime.homes/stream/play.php?slug=zom-100-zombie-ni-naru-made-ni-shitai-100-no-koto", "https://9anime.homes/stream/play.php?slug=kanojo-okarishimasu-3rd-season", "https://9anime.homes/stream/play.php?slug=hataraku-maou-sama-2nd-season", "https://9anime.homes/stream/play.php?slug=rurouni-kenshin-meiji-kenkaku-romantan-2023"] # Clean and preprocess titles cleaned_titles = [re.sub(r'[^a-zA-Z0-9\s-]', '', title).lower().replace(',', '').replace(' - ', '-').replace(' ', '-') for title in titles] # Tokenize and pad sequences tokenizer = Tokenizer(char_level=True) tokenizer.fit_on_texts(cleaned_titles) title_sequences = tokenizer.texts_to_sequences(cleaned_titles) title_sequences = pad_sequences(title_sequences, padding='post') # Convert links to NumPy array links = np.array(links) # Encode the labels (links) as integers label_encoder = LabelEncoder() encoded_links = label_encoder.fit_transform(links) # Create a simple model model = tf.keras.Sequential([ tf.keras.layers.Embedding(input_dim=len(tokenizer.word_index) + 1, output_dim=64), tf.keras.layers.LSTM(64), tf.keras.layers.Dense(len(tokenizer.word_index) + 1, activation='softmax') ]) # Compile the model model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') # Train the model (you should use your own data and appropriate parameters) model.fit(title_sequences, encoded_links, epochs=10, validation_split=0.2) # Use the trained model to generate links def generate_link(title): cleaned_title = re.sub(r'[^a-zA-Z0-9\s-]', '', title).lower().replace(',', '').replace(' - ', '-').replace(' ', '-') sequence = tokenizer.texts_to_sequences([cleaned_title]) padded_sequence = pad_sequences(sequence, padding='post', maxlen=len(title_sequences[0])) prediction = model.predict(padded_sequence) predicted_index = tf.argmax(prediction, axis=-1).numpy()[0] generated_slug = cleaned_title return f"https://9anime.homes/stream/play.php?slug={generated_slug}" # Test the model input_title = "Bleach: Sennen Kessen-hen - Ketsubetsu-tan" output_link = generate_link(input_title) print(output_link)