RICHKEED commited on
Commit
fb47f19
1 Parent(s): bc76352

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +63 -3
README.md CHANGED
@@ -1,3 +1,63 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - SamirXR/NyX-Roleplay
5
+ - Isotonic/human_assistant_conversation
6
+ - itsahyadav/conversation.json
7
+ - flammenai/character-roleplay-DPO
8
+ - Seikaijyu/Classical-Chinese-Roleplay
9
+ language:
10
+ - en
11
+ pipeline_tag: text-classification
12
+ ---
13
+
14
+ This AI predicts if a text is roleplay or not (returns percentage).
15
+ Created by NexusAI Join our discord server: https://discord.gg/7zvkzYutvF
16
+
17
+ # How to use?
18
+
19
+ ```py
20
+ from tensorflow import keras
21
+
22
+ class RPClassifier:
23
+ def __init__(self, model_path='anti_rp.h5'):
24
+ self.model_path = model_path
25
+ self.model = None
26
+ self.load_model()
27
+
28
+ def load_model(self):
29
+ if self.model is None:
30
+ try:
31
+ self.model = keras.models.load_model(self.model_path)
32
+ except (FileNotFoundError, OSError):
33
+ raise Exception("Model file not found")
34
+
35
+ async def predict(self, text):
36
+ if not self.model:
37
+ raise Exception("Model not found")
38
+ try:
39
+ tokenizer = keras.preprocessing.text.Tokenizer()
40
+ tokenizer.fit_on_texts([text])
41
+ sequence = tokenizer.texts_to_sequences([text])
42
+ padded_sequence = keras.preprocessing.sequence.pad_sequences(sequence, maxlen=self.model.input_shape[1])
43
+ prediction = self.model.predict(padded_sequence)[0][0]
44
+ return prediction
45
+ except Exception as e:
46
+ raise Exception("Error occurred while predicting roleplay. {e}")
47
+
48
+ async def analyze(self, input_text):
49
+ rp_percentage = await self.predict(input_text)
50
+ return rp_percentage
51
+
52
+ async def main():
53
+ classifier = RPClassifier()
54
+ while True:
55
+ input_text = input("> ")
56
+ if input_text.lower() == 'exit':
57
+ break
58
+ result = await classifier.analyze(input_text)
59
+ print(result)
60
+
61
+ import asyncio
62
+ asyncio.run(main())
63
+ ```