|
--- |
|
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()) |
|
``` |