Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Türkçe model
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("ytu-ce-cosmos/turkish-gpt2")
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("ytu-ce-cosmos/turkish-gpt2")
|
| 7 |
+
|
| 8 |
+
def dusun(prompt, max_length=150):
|
| 9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 10 |
+
outputs = model.generate(**inputs, max_length=max_length, do_sample=True, temperature=0.8)
|
| 11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
+
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=dusun,
|
| 15 |
+
inputs=[
|
| 16 |
+
gr.Textbox(label="Türkçe Prompt", lines=3),
|
| 17 |
+
gr.Slider(50, 200, value=100, label="Uzunluk")
|
| 18 |
+
],
|
| 19 |
+
outputs=gr.Textbox(label="Üretilen Metin", lines=10),
|
| 20 |
+
title="🇹🇷 Türkçe GPT-2",
|
| 21 |
+
examples=[
|
| 22 |
+
["Bir varmış bir yokmuş"],
|
| 23 |
+
["Yapay zeka geleceği"],
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
demo.launch()
|