File size: 1,363 Bytes
7260118
 
 
 
 
 
 
 
 
 
457f99e
7260118
 
 
91c43fd
7260118
 
 
 
 
 
 
 
 
 
 
 
 
457f99e
 
7260118
 
 
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
from transformers import GPT2LMHeadModel, GPT2Tokenizer
import gradio as gr

# Model ve tokenizer'ı yükle
model_name = "eminAydin/turkish-gpt2-mini-M1-cleaned-sports720k-10ep"
tokenizer = GPT2Tokenizer.from_pretrained("ytu-ce-cosmos/turkish-gpt2")
tokenizer.pad_token = tokenizer.eos_token
model = GPT2LMHeadModel.from_pretrained(model_name)
# parametrelere bağlı olarak text üretmek
generation_config = {
    'temperature': 0.7,       # rastgelelik için artırabilirim
    "do_sample": True,
    "max_new_tokens": 50,
    'top_p': 0.9,             # Use top-p sampling
    'repetition_penalty': 1.3, # tekrarı azaltır fakat anlamı bozabilir.
    'eos_token_id': tokenizer.eos_token_id, # Set eos_token_id
    'pad_token_id': tokenizer.pad_token_id,  # Set pad_token_id
}

def launch(input):
    input_ids = tokenizer.encode(input, return_tensors="pt")
    output = model.generate(input_ids, num_return_sequences=1, **generation_config)
    output = tokenizer.decode(output[0], skip_special_tokens=True)
    return output

iface = gr.Interface(launch,
                         inputs="text", 
                         outputs="text",
                         title="Turkish Text Generation with GPT-2",
                         description="Enter a Turkish prompt and generate text using GPT-2.",
                         theme="default")

iface.launch()