Clemylia commited on
Commit
d39f364
·
verified ·
1 Parent(s): 78c63c0

Create prenma.js

Browse files
Files changed (1) hide show
  1. prenma.js +75 -0
prenma.js ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // La classe de ton modèle Prenma
2
+ class PrenmaModel {
3
+
4
+ // Cette méthode est requise par transformer.js, mais ne fait rien
5
+ // car notre modèle ne nécessite pas de chargement externe.
6
+ static async getInstance(progress_callback = null) {
7
+ return new PrenmaModel();
8
+ }
9
+
10
+ // La méthode de génération, ajustée pour prendre des options
11
+ async generate(options) {
12
+ // Définition des caractères et des options
13
+ const vowels = 'aeiouy';
14
+ const consonants = 'bcdfghjklmnpqrstvwxyz';
15
+ const numbers = '0123456789';
16
+
17
+ // Les options par défaut si elles ne sont pas fournies
18
+ const { length = 8, style = 'fantasy', includeNumbers = false } = options;
19
+
20
+ function getRandomChar(str) {
21
+ return str[Math.floor(Math.random() * str.length)];
22
+ }
23
+
24
+ function generateFantasyName(len) {
25
+ let name = '';
26
+ let lastCharType = Math.random() < 0.5 ? 'vowel' : 'consonant';
27
+
28
+ for (let i = 0; i < len; i++) {
29
+ if (lastCharType === 'vowel') {
30
+ name += getRandomChar(consonants);
31
+ lastCharType = 'consonant';
32
+ } else {
33
+ name += getRandomChar(vowels);
34
+ lastCharType = 'vowel';
35
+ }
36
+ }
37
+ return name.charAt(0).toUpperCase() + name.slice(1);
38
+ }
39
+
40
+ function generateRealName() {
41
+ const firstNames = ['Alex', 'Léa', 'Lucas', 'Emma', 'Hugo', 'Chloé', 'Théo', 'Manon', 'Louise', 'Clementine', 'charlotte', 'Nicole', 'Rose', 'Françoise', 'Elsa', 'Julie', 'Karine', 'Emylie', 'Sylvie', 'Antoine', 'Mïa', "Elena", 'Mathieu', 'Clemence', 'Xavier', 'Laura', 'Veronique', 'Gloria', 'Louna', 'Oceanne', 'Violetine', 'Nora', 'Leo', 'Valentina', 'Nina', 'Lora', 'Dania', 'Sandra', 'Anaselia', 'Anastasia', 'Vincent', 'Olga', 'Maya', 'Lucie', 'Sindy', 'Sandy', 'Wendy', 'Julien', 'Clementine', 'Xavier', 'Georgia'];
42
+ const lastNames = ['Martin', 'Dubois', 'Thomas', 'Robert', 'Petit', 'Durand', 'Leroy', 'Moreau', 'Garcia', 'Bonnet', 'Castorina', 'Baril', 'Geneviere', 'Jonia', 'Mazoo', 'Noca', 'Cary', 'Astro', 'Grosiel', 'Lebois', 'Marte', 'Reno', 'Luminis', 'Zexir', 'Norza', 'Zilda', 'Kachallit', 'Vanilla', 'Durand', 'Bonnard', 'Le marseille', 'Nicotouche', 'Montaise', 'Dubeure', 'Carco', 'Tary'];
43
+ const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
44
+ const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)];
45
+ return randomFirstName + ' ' + randomLastName;
46
+ }
47
+
48
+ function addNumbers(name) {
49
+ let numLength = Math.floor(Math.random() * 4) + 1;
50
+ let numbersPart = '';
51
+ for (let i = 0; i < numLength; i++) {
52
+ numbersPart += getRandomChar(numbers);
53
+ }
54
+ return name + numbersPart;
55
+ }
56
+
57
+ // Génération du nom basée sur les options
58
+ let generatedName;
59
+ if (style === 'fantasy') {
60
+ generatedName = generateFantasyName(length);
61
+ } else {
62
+ generatedName = generateRealName();
63
+ }
64
+
65
+ if (includeNumbers) {
66
+ generatedName = addNumbers(generatedName);
67
+ }
68
+
69
+ // Le format de sortie doit correspondre à ce que Hugging Face s'attend
70
+ return [{ generated_text: generatedName }];
71
+ }
72
+ }
73
+
74
+ // Exportez la classe pour qu'elle puisse être utilisée
75
+ export default PrenmaModel;