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
+
import json
|
| 5 |
+
import os
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
+
|
| 9 |
+
# Kelimeleri yükle
|
| 10 |
+
kelimeler = pd.read_csv("kelimeler.csv")
|
| 11 |
+
kelimeler = kelimeler.sample(frac=1).reset_index(drop=True) # Karıştır
|
| 12 |
+
|
| 13 |
+
# Kullanıcı oturumu için değişkenler
|
| 14 |
+
user_session = {
|
| 15 |
+
"isim": "",
|
| 16 |
+
"soru_index": 0,
|
| 17 |
+
"dogru": 0,
|
| 18 |
+
"yanlis": 0,
|
| 19 |
+
"cevaplar": []
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
SONUC_DOSYASI = "results.json"
|
| 23 |
+
|
| 24 |
+
# İlk kullanıcı girişi
|
| 25 |
+
def baslat(isim):
|
| 26 |
+
user_session["isim"] = isim
|
| 27 |
+
user_session["soru_index"] = 0
|
| 28 |
+
user_session["dogru"] = 0
|
| 29 |
+
user_session["yanlis"] = 0
|
| 30 |
+
user_session["cevaplar"] = []
|
| 31 |
+
return gr.update(visible=True), gr.update(visible=False), get_soru()
|
| 32 |
+
|
| 33 |
+
# Soru getir
|
| 34 |
+
def get_soru():
|
| 35 |
+
idx = user_session["soru_index"]
|
| 36 |
+
if idx >= 15:
|
| 37 |
+
kaydet_sonuc()
|
| 38 |
+
return "Test tamamlandı.", None, "", "", False
|
| 39 |
+
satir = kelimeler.iloc[idx]
|
| 40 |
+
return f"{idx+1}. Kelime:", satir["audio"], "", "", True
|
| 41 |
+
|
| 42 |
+
# Cevap kontrolü ve bir sonraki soruya geçiş
|
| 43 |
+
def kontrol_et(turkce_cevap):
|
| 44 |
+
idx = user_session["soru_index"]
|
| 45 |
+
satir = kelimeler.iloc[idx]
|
| 46 |
+
dogru_mu = turkce_cevap.strip().lower() == satir["turkish"].lower()
|
| 47 |
+
|
| 48 |
+
user_session["cevaplar"].append({
|
| 49 |
+
"soru": satir["english"],
|
| 50 |
+
"cevap": turkce_cevap,
|
| 51 |
+
"dogru_cevap": satir["turkish"],
|
| 52 |
+
"dogru_mu": dogru_mu
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
if dogru_mu:
|
| 56 |
+
user_session["dogru"] += 1
|
| 57 |
+
geribildirim = "✅ Doğru!"
|
| 58 |
+
else:
|
| 59 |
+
user_session["yanlis"] += 1
|
| 60 |
+
geribildirim = f"❌ Yanlış! Doğru: {satir['turkish']}"
|
| 61 |
+
|
| 62 |
+
user_session["soru_index"] += 1
|
| 63 |
+
soru, ses, _, _, aktif = get_soru()
|
| 64 |
+
return geribildirim, soru, ses, "", aktif
|
| 65 |
+
|
| 66 |
+
# Sonuçları kaydet
|
| 67 |
+
def kaydet_sonuc():
|
| 68 |
+
sonuc = {
|
| 69 |
+
"isim": user_session["isim"],
|
| 70 |
+
"dogru": user_session["dogru"],
|
| 71 |
+
"yanlis": user_session["yanlis"],
|
| 72 |
+
"zaman": datetime.now().isoformat()
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if os.path.exists(SONUC_DOSYASI):
|
| 76 |
+
with open(SONUC_DOSYASI, "r") as f:
|
| 77 |
+
veriler = json.load(f)
|
| 78 |
+
else:
|
| 79 |
+
veriler = []
|
| 80 |
+
|
| 81 |
+
veriler.append(sonuc)
|
| 82 |
+
|
| 83 |
+
with open(SONUC_DOSYASI, "w") as f:
|
| 84 |
+
json.dump(veriler, f)
|
| 85 |
+
|
| 86 |
+
# Öğretmen ekranı (şifreli)
|
| 87 |
+
def ogretmen_paneli(sifre):
|
| 88 |
+
if sifre != "5555":
|
| 89 |
+
return "❌ Hatalı şifre", None
|
| 90 |
+
|
| 91 |
+
if not os.path.exists(SONUC_DOSYASI):
|
| 92 |
+
return "Henüz kayıtlı veri yok.", None
|
| 93 |
+
|
| 94 |
+
with open(SONUC_DOSYASI, "r") as f:
|
| 95 |
+
veriler = json.load(f)
|
| 96 |
+
|
| 97 |
+
df = pd.DataFrame(veriler)
|
| 98 |
+
|
| 99 |
+
# Grafik oluştur
|
| 100 |
+
plt.figure(figsize=(6,4))
|
| 101 |
+
plt.bar(df["isim"], df["dogru"], label="Doğru", color="green")
|
| 102 |
+
plt.bar(df["isim"], df["yanlis"], bottom=df["dogru"], label="Yanlış", color="red")
|
| 103 |
+
plt.xlabel("Öğrenci")
|
| 104 |
+
plt.ylabel("Soru Sayısı")
|
| 105 |
+
plt.title("Öğrenci Performansları")
|
| 106 |
+
plt.legend()
|
| 107 |
+
grafik_yolu = "grafik.png"
|
| 108 |
+
plt.tight_layout()
|
| 109 |
+
plt.savefig(grafik_yolu)
|
| 110 |
+
plt.close()
|
| 111 |
+
|
| 112 |
+
return "✅ Giriş başarılı", grafik_yolu
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# Arayüz
|
| 116 |
+
with gr.Blocks() as demo:
|
| 117 |
+
gr.Markdown("## 📚 İngilizce Kelime Testi (15 Soru)")
|
| 118 |
+
|
| 119 |
+
with gr.Row():
|
| 120 |
+
isim_input = gr.Textbox(label="Adınızı girin")
|
| 121 |
+
baslat_btn = gr.Button("Teste Başla")
|
| 122 |
+
|
| 123 |
+
soru_kutusu = gr.Textbox(label="Soru", interactive=False, visible=False)
|
| 124 |
+
ses_kutusu = gr.Audio(label="Kelimenin Telaffuzu", interactive=False)
|
| 125 |
+
cevap_input = gr.Textbox(label="Türkçesini Yazınız")
|
| 126 |
+
cevap_btn = gr.Button("Cevabı Kontrol Et")
|
| 127 |
+
geribildirim = gr.Textbox(label="Geri Bildirim", interactive=False)
|
| 128 |
+
|
| 129 |
+
cevap_input.visible = False
|
| 130 |
+
cevap_btn.visible = False
|
| 131 |
+
ses_kutusu.visible = False
|
| 132 |
+
|
| 133 |
+
def arayuz_gizle():
|
| 134 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 135 |
+
|
| 136 |
+
baslat_btn.click(baslat, inputs=isim_input,
|
| 137 |
+
outputs=[soru_kutusu, isim_input, ses_kutusu])
|
| 138 |
+
|
| 139 |
+
cevap_btn.click(kontrol_et, inputs=cevap_input,
|
| 140 |
+
outputs=[geribildirim, soru_kutusu, ses_kutusu, cevap_input, cevap_btn])
|
| 141 |
+
|
| 142 |
+
# Öğretmen Girişi
|
| 143 |
+
with gr.Accordion("👩🏫 Öğretmen Girişi", open=False):
|
| 144 |
+
sifre = gr.Textbox(label="Şifre", type="password")
|
| 145 |
+
sifre_btn = gr.Button("Giriş Yap")
|
| 146 |
+
sonuc_mesaj = gr.Textbox(label="Durum", interactive=False)
|
| 147 |
+
grafik = gr.Image()
|
| 148 |
+
|
| 149 |
+
sifre_btn.click(ogretmen_paneli, inputs=sifre, outputs=[sonuc_mesaj, grafik])
|
| 150 |
+
|
| 151 |
+
demo.launch()
|