Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Model ve tokenizer'ı yükle
|
| 5 |
+
model_name = "eminAydin/turkish-gpt2-mini-M1-cleaned-sports720k-10ep"
|
| 6 |
+
tokenizer = GPT2Tokenizer.from_pretrained("ytu-ce-cosmos/turkish-gpt2")
|
| 7 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 8 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 9 |
+
# parametrelere bağlı olarak text üretmek
|
| 10 |
+
generation_config = {
|
| 11 |
+
'temperature': 0.1, # rastgelelik için artırabilirim
|
| 12 |
+
"do_sample": True,
|
| 13 |
+
"max_new_tokens": 50,
|
| 14 |
+
'top_p': 0.9, # Use top-p sampling
|
| 15 |
+
'repetition_penalty': 1.1, # tekrarı azaltır fakat anlamı bozabilir.
|
| 16 |
+
'eos_token_id': tokenizer.eos_token_id, # Set eos_token_id
|
| 17 |
+
'pad_token_id': tokenizer.pad_token_id, # Set pad_token_id
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
def launch(input):
|
| 21 |
+
input_ids = tokenizer.encode(input, return_tensors="pt")
|
| 22 |
+
output = model.generate(input_ids, num_return_sequences=1, **generation_config)
|
| 23 |
+
output = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 24 |
+
return output
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(launch,
|
| 27 |
+
inputs="text",
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="Text Generation with GPT-2",
|
| 30 |
+
description="Enter a prompt and generate text using GPT-2.",
|
| 31 |
+
theme="default")
|
| 32 |
+
|
| 33 |
+
iface.launch()
|