Spaces:
Sleeping
Sleeping
File size: 5,187 Bytes
e0cb3cf 73040b0 e0cb3cf 2e86c36 73040b0 ee69a75 73040b0 ee69a75 2ef3b8d e0cb3cf 2e86c36 e0cb3cf 2e86c36 e0cb3cf 73040b0 2e86c36 e0cb3cf 2e86c36 ee69a75 2e86c36 ee69a75 2e86c36 ee69a75 2e86c36 ee69a75 2e86c36 e0cb3cf 2e86c36 e0cb3cf 2e86c36 e0cb3cf ee69a75 e0cb3cf 2e86c36 e0cb3cf 2e86c36 e0cb3cf 2e86c36 73040b0 2e86c36 ee69a75 e0cb3cf 2e86c36 ee69a75 2e86c36 ee69a75 2e86c36 ee69a75 e0cb3cf ee69a75 73040b0 2e86c36 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | import gradio as gr
import pandas as pd
import random
import json
import os
from datetime import datetime
import matplotlib.pyplot as plt
from gtts import gTTS
# Ses üretim klasörü
TEMP_SESLER_KLASORU = "temp_sesler"
os.makedirs(TEMP_SESLER_KLASORU, exist_ok=True)
# Ses üretici fonksiyon
def ses_uret(kelime):
yol = f"{TEMP_SESLER_KLASORU}/{kelime}.mp3"
if not os.path.exists(yol):
tts = gTTS(text=kelime, lang='en')
tts.save(yol)
return yol
# Kelimeleri yükle
tum_kelimeler = pd.read_csv("kelimeler.csv")
# Her testte rasgele 15 kelime seç
kelimeler = tum_kelimeler.sample(n=15).reset_index(drop=True)
# Kullanıcı oturum verileri
user_session = {
"isim": "",
"soru_index": 0,
"dogru": 0,
"yanlis": 0,
"cevaplar": []
}
SONUC_DOSYASI = "results.json"
# Soru getirme fonksiyonu
def get_soru():
idx = user_session["soru_index"]
if idx >= 15:
kaydet_sonuc()
return "Test tamamlandı.", None, "", "", False
satir = kelimeler.iloc[idx]
ses_yolu = ses_uret(satir["english"])
return f"{idx+1}. Soru", ses_yolu, f"🔤 İngilizce: **{satir['english']}**", "", True
# Test başlat
def baslat(isim):
if not isim.strip():
raise gr.Error("⚠️ Lütfen isminizi giriniz.")
user_session["isim"] = isim
user_session["soru_index"] = 0
user_session["dogru"] = 0
user_session["yanlis"] = 0
user_session["cevaplar"] = []
soru, ses, yazilis, _, _ = get_soru()
return (
soru, # soru_kutusu
gr.update(visible=False),# isim_input
ses, # ses_kutusu
yazilis, # kelime_gorunum
gr.update(visible=True), # cevap_input
gr.update(visible=True) # cevap_btn
)
# Cevap kontrolü
def kontrol_et(turkce_cevap):
idx = user_session["soru_index"]
satir = kelimeler.iloc[idx]
dogru_mu = turkce_cevap.strip().lower() == satir["turkish"].lower()
user_session["cevaplar"].append({
"soru": satir["english"],
"cevap": turkce_cevap,
"dogru_cevap": satir["turkish"],
"dogru_mu": dogru_mu
})
if dogru_mu:
user_session["dogru"] += 1
geribildirim = "✅ Doğru!"
else:
user_session["yanlis"] += 1
geribildirim = f"❌ Yanlış! Doğru: {satir['turkish']}"
user_session["soru_index"] += 1
soru, ses, yazilis, _, aktif = get_soru()
return geribildirim, soru, ses, yazilis, "", aktif
# Sonuç kaydet
def kaydet_sonuc():
sonuc = {
"isim": user_session["isim"],
"dogru": user_session["dogru"],
"yanlis": user_session["yanlis"],
"zaman": datetime.now().isoformat()
}
if os.path.exists(SONUC_DOSYASI):
with open(SONUC_DOSYASI, "r") as f:
veriler = json.load(f)
else:
veriler = []
veriler.append(sonuc)
with open(SONUC_DOSYASI, "w") as f:
json.dump(veriler, f)
# Öğretmen paneli
def ogretmen_paneli(sifre):
if sifre != "5555":
return "❌ Hatalı şifre", None
if not os.path.exists(SONUC_DOSYASI):
return "Henüz kayıtlı veri yok.", None
with open(SONUC_DOSYASI, "r") as f:
veriler = json.load(f)
df = pd.DataFrame(veriler)
# Grafik oluştur
plt.figure(figsize=(6,4))
plt.bar(df["isim"], df["dogru"], label="Doğru", color="green")
plt.bar(df["isim"], df["yanlis"], bottom=df["dogru"], label="Yanlış", color="red")
plt.xlabel("Öğrenci")
plt.ylabel("Soru Sayısı")
plt.title("Öğrenci Performansları")
plt.legend()
grafik_yolu = "grafik.png"
plt.tight_layout()
plt.savefig(grafik_yolu)
plt.close()
return "✅ Giriş başarılı", grafik_yolu
# Gradio arayüzü
with gr.Blocks() as demo:
gr.Markdown("## 📚 İngilizce Kelime Testi (15 Soru)")
with gr.Row():
isim_input = gr.Textbox(label="Adınızı girin")
baslat_btn = gr.Button("Teste Başla")
soru_kutusu = gr.Textbox(label="Soru", interactive=False, visible=True)
ses_kutusu = gr.Audio(label="Kelimenin Telaffuzu", interactive=False, type="filepath")
kelime_gorunum = gr.Markdown(visible=True)
cevap_input = gr.Textbox(label="Türkçesini Yazınız", visible=False)
cevap_btn = gr.Button("Cevabı Kontrol Et", visible=False)
geribildirim = gr.Textbox(label="Geri Bildirim", interactive=False)
# Bağlantılar
baslat_btn.click(
baslat,
inputs=isim_input,
outputs=[soru_kutusu, isim_input, ses_kutusu, kelime_gorunum, cevap_input, cevap_btn]
)
cevap_btn.click(
kontrol_et,
inputs=cevap_input,
outputs=[geribildirim, soru_kutusu, ses_kutusu, kelime_gorunum, cevap_input, cevap_btn]
)
with gr.Accordion("👩🏫 Öğretmen Girişi", open=False):
sifre = gr.Textbox(label="Şifre", type="password")
sifre_btn = gr.Button("Giriş Yap")
sonuc_mesaj = gr.Textbox(label="Durum", interactive=False)
grafik = gr.Image()
sifre_btn.click(
ogretmen_paneli,
inputs=sifre,
outputs=[sonuc_mesaj, grafik]
)
demo.launch()
|