Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Kullanacağımız modelin adı
|
| 5 |
+
MODEL_NAME = "ytu-ce-cosmos/turkish-gpt2-large"
|
| 6 |
+
|
| 7 |
+
# Tokenizer ve modeli yükle
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 10 |
+
|
| 11 |
+
def respond(prompt: str) -> str:
|
| 12 |
+
# Girdi metnini tokenize et
|
| 13 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 14 |
+
# Yanıt üret
|
| 15 |
+
outputs = model.generate(**inputs, max_new_tokens=150)
|
| 16 |
+
# Token’ları düz metne çevir ve döndür
|
| 17 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
|
| 19 |
+
# Gradio arayüzü
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=respond,
|
| 22 |
+
inputs=gr.Textbox(lines=4, placeholder="Sorunuzu buraya yazın..."),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="AR Güneş Sistemi Asistanı",
|
| 25 |
+
description="AR projeniz için Türkçe sohbet asistanı. Bir cümle yazıp Gönder’e tıklayın."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|