omer123tr commited on
Commit
19ef39e
·
verified ·
1 Parent(s): 12a2d59

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ model_id = "ytu-ce-cosmos/Turkish-Gemma-9b-T1"
6
+
7
+ # Model ve tokenizer yükleme
8
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ model_id,
11
+ torch_dtype=torch.bfloat16,
12
+ device_map="auto"
13
+ )
14
+
15
+ def generate_question(topic):
16
+ prompt = f"""
17
+ Aşağıdaki konuda bana 1 adet soru, 1 doğru cevap ve 1 yanlış cevap üret:
18
+ Konu: {topic}
19
+
20
+ Format:
21
+ Soru:
22
+ Doğru Cevap:
23
+ Yanlış Cevap:
24
+ """
25
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
26
+ output = model.generate(
27
+ **inputs,
28
+ max_new_tokens=200,
29
+ temperature=0.7,
30
+ top_p=0.95,
31
+ top_k=20
32
+ )
33
+
34
+ result = tokenizer.decode(output[0], skip_special_tokens=True)
35
+
36
+ return result
37
+
38
+ # Gradio Arayüzü
39
+ with gr.Blocks() as app:
40
+ gr.Markdown("# 🇹🇷 Turkish Gemma – Soru Üretici")
41
+ gr.Markdown("### Bir konu yaz ve modelden **soru + doğru cevap + yanlış cevap** gelsin.")
42
+
43
+ topic = gr.Textbox(label="Konu", placeholder="Örnek: Osmanlı Tarihi")
44
+ output = gr.Textbox(label="Model Çıktısı")
45
+
46
+ btn = gr.Button("Üret")
47
+
48
+ btn.click(generate_question, inputs=topic, outputs=output)
49
+
50
+ app.launch()