File size: 1,868 Bytes
fb47f19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
license: apache-2.0
datasets:
- SamirXR/NyX-Roleplay
- Isotonic/human_assistant_conversation
- itsahyadav/conversation.json
- flammenai/character-roleplay-DPO
- Seikaijyu/Classical-Chinese-Roleplay
language:
- en
pipeline_tag: text-classification
---

This AI predicts if a text is roleplay or not (returns percentage).
Created by NexusAI Join our discord server: https://discord.gg/7zvkzYutvF

# How to use?

```py
from tensorflow import keras

class RPClassifier:
    def __init__(self, model_path='anti_rp.h5'):
        self.model_path = model_path
        self.model = None
        self.load_model()

    def load_model(self):
        if self.model is None:
            try:
                self.model = keras.models.load_model(self.model_path)
            except (FileNotFoundError, OSError):
                raise Exception("Model file not found")

    async def predict(self, text):
        if not self.model:
            raise Exception("Model not found")
        try:
            tokenizer = keras.preprocessing.text.Tokenizer()
            tokenizer.fit_on_texts([text])
            sequence = tokenizer.texts_to_sequences([text])
            padded_sequence = keras.preprocessing.sequence.pad_sequences(sequence, maxlen=self.model.input_shape[1])
            prediction = self.model.predict(padded_sequence)[0][0]
            return prediction
        except Exception as e:
            raise Exception("Error occurred while predicting roleplay. {e}")

    async def analyze(self, input_text):
        rp_percentage = await self.predict(input_text)
        return rp_percentage

async def main():
    classifier = RPClassifier()
    while True:
        input_text = input("> ")
        if input_text.lower() == 'exit':
            break
        result = await classifier.analyze(input_text)
        print(result)

import asyncio
asyncio.run(main()) 
```