File size: 3,239 Bytes
d39f364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
// La classe de ton modèle Prenma
class PrenmaModel {

  // Cette méthode est requise par transformer.js, mais ne fait rien
  // car notre modèle ne nécessite pas de chargement externe.
  static async getInstance(progress_callback = null) {
    return new PrenmaModel();
  }

  // La méthode de génération, ajustée pour prendre des options
  async generate(options) {
    // Définition des caractères et des options
    const vowels = 'aeiouy';
    const consonants = 'bcdfghjklmnpqrstvwxyz';
    const numbers = '0123456789';

    // Les options par défaut si elles ne sont pas fournies
    const { length = 8, style = 'fantasy', includeNumbers = false } = options;

    function getRandomChar(str) {
      return str[Math.floor(Math.random() * str.length)];
    }

    function generateFantasyName(len) {
      let name = '';
      let lastCharType = Math.random() < 0.5 ? 'vowel' : 'consonant';

      for (let i = 0; i < len; i++) {
        if (lastCharType === 'vowel') {
          name += getRandomChar(consonants);
          lastCharType = 'consonant';
        } else {
          name += getRandomChar(vowels);
          lastCharType = 'vowel';
        }
      }
      return name.charAt(0).toUpperCase() + name.slice(1);
    }

    function generateRealName() {
        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'];
        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'];
        const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)];
        const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)];
        return randomFirstName + ' ' + randomLastName;
    }

    function addNumbers(name) {
        let numLength = Math.floor(Math.random() * 4) + 1;
        let numbersPart = '';
        for (let i = 0; i < numLength; i++) {
            numbersPart += getRandomChar(numbers);
        }
        return name + numbersPart;
    }

    // Génération du nom basée sur les options
    let generatedName;
    if (style === 'fantasy') {
      generatedName = generateFantasyName(length);
    } else {
      generatedName = generateRealName();
    }

    if (includeNumbers) {
      generatedName = addNumbers(generatedName);
    }

    // Le format de sortie doit correspondre à ce que Hugging Face s'attend
    return [{ generated_text: generatedName }];
  }
}

// Exportez la classe pour qu'elle puisse être utilisée
export default PrenmaModel;