Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
MODEL_ID = "userdotcs/gpt-oss-20b-turkish-correction-finetuned"
|
| 6 |
+
BASE_MODEL = "unsloth/gpt-oss-20b" # veya base repo adı neyse
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 9 |
+
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
+
MODEL_ID,
|
| 12 |
+
torch_dtype=torch.float16,
|
| 13 |
+
device_map="auto",
|
| 14 |
+
trust_remote_code=True
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def generate(prompt):
|
| 18 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 19 |
+
out = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_new_tokens=256,
|
| 22 |
+
pad_token_id=tokenizer.eos_token_id
|
| 23 |
+
)
|
| 24 |
+
text = tokenizer.decode(out[0], skip_special_tokens=True)
|
| 25 |
+
return text
|
| 26 |
+
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=generate,
|
| 29 |
+
inputs=gr.Textbox(lines=4, placeholder="Bir metin gir…"),
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="Turkish Correction GPT-OSS-20B"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|