File size: 1,163 Bytes
c060b6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline


def generate(text, the_model, max_length, temperature, repetition_penalty):
    generator = pipeline("text-generation", model=the_model)
    result = generator(
        text,
        num_return_sequences=1,
        max_length=max_length,
        temperature=temperature,
        repetition_penalty=repetition_penalty,
        no_repeat_ngram_size=2,
        early_stopping=False,
    )
    return result[0]["generated_text"]


def complete_with_gpt(
    text, context, the_model, max_length, temperature, repetition_penalty
):
    # Use the last [context] characters of the text as context
    max_length = max_length + context
    return generate(
        text[-context:], the_model, max_length, temperature, repetition_penalty
    )


# complete_with_gpt("I am a language model",200,'gpt2-medium',1500,0.7,1.5)
# def generate(genre:str,topic:str,main_name:str,type_of_main_character:str,antagonist_name:str,
#              antagonist_type:str,supporting_character_name:str,supporting_char_type:str,settings:str,
#              resoluton:str,chapter:int
#              ):
#     chapter_text={}
#     for x in range(chapter):0