Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,13 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
| 3 |
|
| 4 |
model_name = "google/mt5-small"
|
| 5 |
|
| 6 |
-
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
| 8 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
-
def generate_text(
|
|
|
|
|
|
|
| 11 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 12 |
outputs = model.generate(
|
| 13 |
**inputs,
|
|
@@ -22,8 +24,8 @@ demo = gr.Interface(
|
|
| 22 |
fn=generate_text,
|
| 23 |
inputs=gr.Textbox(label="Türkçe Metin Başlangıcı", placeholder="Bir cümle yaz..."),
|
| 24 |
outputs=gr.Textbox(label="Üretilen Metin"),
|
| 25 |
-
title="Türkçe Metin Üretici (MT5-Small
|
| 26 |
-
description="
|
| 27 |
)
|
| 28 |
|
| 29 |
demo.launch()
|
|
|
|
| 3 |
|
| 4 |
model_name = "google/mt5-small"
|
| 5 |
|
| 6 |
+
# Slow tokenizer ile çalıştırıyoruz
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
| 8 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
+
def generate_text(user_input):
|
| 11 |
+
# Prefix ekleyerek modelin plain text üretmesini sağlıyoruz
|
| 12 |
+
prompt = "write in Turkish: " + user_input
|
| 13 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 14 |
outputs = model.generate(
|
| 15 |
**inputs,
|
|
|
|
| 24 |
fn=generate_text,
|
| 25 |
inputs=gr.Textbox(label="Türkçe Metin Başlangıcı", placeholder="Bir cümle yaz..."),
|
| 26 |
outputs=gr.Textbox(label="Üretilen Metin"),
|
| 27 |
+
title="Türkçe Metin Üretici (MT5-Small)",
|
| 28 |
+
description="CPU dostu, hızlı ve basit Türkçe metin üretici."
|
| 29 |
)
|
| 30 |
|
| 31 |
demo.launch()
|