beejaytmg commited on
Commit
8a8f9e4
·
1 Parent(s): d63134f

Create model.py

Browse files
Files changed (1) hide show
  1. model.py +54 -0
model.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow.keras.preprocessing.text import Tokenizer
5
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
6
+ from sklearn.preprocessing import LabelEncoder
7
+
8
+ # Sample dataset (you should use your own dataset)
9
+ 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)"]
10
+ 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"]
11
+
12
+ # Clean and preprocess titles
13
+ cleaned_titles = [re.sub(r'[^a-zA-Z0-9\s-]', '', title).lower().replace(',', '').replace(' - ', '-').replace(' ', '-') for title in titles]
14
+
15
+ # Tokenize and pad sequences
16
+ tokenizer = Tokenizer(char_level=True)
17
+ tokenizer.fit_on_texts(cleaned_titles)
18
+ title_sequences = tokenizer.texts_to_sequences(cleaned_titles)
19
+ title_sequences = pad_sequences(title_sequences, padding='post')
20
+
21
+ # Convert links to NumPy array
22
+ links = np.array(links)
23
+
24
+ # Encode the labels (links) as integers
25
+ label_encoder = LabelEncoder()
26
+ encoded_links = label_encoder.fit_transform(links)
27
+
28
+ # Create a simple model
29
+ model = tf.keras.Sequential([
30
+ tf.keras.layers.Embedding(input_dim=len(tokenizer.word_index) + 1, output_dim=64),
31
+ tf.keras.layers.LSTM(64),
32
+ tf.keras.layers.Dense(len(tokenizer.word_index) + 1, activation='softmax')
33
+ ])
34
+
35
+ # Compile the model
36
+ model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
37
+
38
+ # Train the model (you should use your own data and appropriate parameters)
39
+ model.fit(title_sequences, encoded_links, epochs=10, validation_split=0.2)
40
+
41
+ # Use the trained model to generate links
42
+ def generate_link(title):
43
+ cleaned_title = re.sub(r'[^a-zA-Z0-9\s-]', '', title).lower().replace(',', '').replace(' - ', '-').replace(' ', '-')
44
+ sequence = tokenizer.texts_to_sequences([cleaned_title])
45
+ padded_sequence = pad_sequences(sequence, padding='post', maxlen=len(title_sequences[0]))
46
+ prediction = model.predict(padded_sequence)
47
+ predicted_index = tf.argmax(prediction, axis=-1).numpy()[0]
48
+ generated_slug = cleaned_title
49
+ return f"https://9anime.homes/stream/play.php?slug={generated_slug}"
50
+
51
+ # Test the model
52
+ input_title = "Bleach: Sennen Kessen-hen - Ketsubetsu-tan"
53
+ output_link = generate_link(input_title)
54
+ print(output_link)