Phytgoras commited on
Commit
ee69a75
·
verified ·
1 Parent(s): 87a2778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -35
app.py CHANGED
@@ -7,11 +7,11 @@ from datetime import datetime
7
  import matplotlib.pyplot as plt
8
  from gtts import gTTS
9
 
10
- # Ses üretme klasörü
11
  TEMP_SESLER_KLASORU = "temp_sesler"
12
  os.makedirs(TEMP_SESLER_KLASORU, exist_ok=True)
13
 
14
- # Ses üretici
15
  def ses_uret(kelime):
16
  yol = f"{TEMP_SESLER_KLASORU}/{kelime}.mp3"
17
  if not os.path.exists(yol):
@@ -19,11 +19,11 @@ def ses_uret(kelime):
19
  tts.save(yol)
20
  return yol
21
 
22
- # Kelimeleri yükle
23
  kelimeler = pd.read_csv("kelimeler.csv")
24
  kelimeler = kelimeler.sample(frac=1).reset_index(drop=True) # Karıştır
25
 
26
- # Oturum yönetimi
27
  user_session = {
28
  "isim": "",
29
  "soru_index": 0,
@@ -34,16 +34,7 @@ user_session = {
34
 
35
  SONUC_DOSYASI = "results.json"
36
 
37
- # Kullanıcı başlatma
38
- def baslat(isim):
39
- user_session["isim"] = isim
40
- user_session["soru_index"] = 0
41
- user_session["dogru"] = 0
42
- user_session["yanlis"] = 0
43
- user_session["cevaplar"] = []
44
- return gr.update(visible=True), gr.update(visible=False), *get_soru()
45
-
46
- # ✅ Soru getirici
47
  def get_soru():
48
  idx = user_session["soru_index"]
49
  if idx >= 15:
@@ -53,7 +44,25 @@ def get_soru():
53
  ses_yolu = ses_uret(satir["english"])
54
  return f"{idx+1}. Kelime: {satir['english']}", ses_yolu, "", "", True
55
 
56
- # Cevap kontrolü ve geçiş
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def kontrol_et(turkce_cevap):
58
  idx = user_session["soru_index"]
59
  satir = kelimeler.iloc[idx]
@@ -77,7 +86,7 @@ def kontrol_et(turkce_cevap):
77
  soru, ses, _, _, aktif = get_soru()
78
  return geribildirim, soru, ses, "", aktif
79
 
80
- # Sonuçları kaydet
81
  def kaydet_sonuc():
82
  sonuc = {
83
  "isim": user_session["isim"],
@@ -97,7 +106,7 @@ def kaydet_sonuc():
97
  with open(SONUC_DOSYASI, "w") as f:
98
  json.dump(veriler, f)
99
 
100
- # Öğretmen şifreli panel
101
  def ogretmen_paneli(sifre):
102
  if sifre != "5555":
103
  return "❌ Hatalı şifre", None
@@ -110,7 +119,8 @@ def ogretmen_paneli(sifre):
110
 
111
  df = pd.DataFrame(veriler)
112
 
113
- # Grafik oluştur
 
114
  plt.figure(figsize=(6,4))
115
  plt.bar(df["isim"], df["dogru"], label="Doğru", color="green")
116
  plt.bar(df["isim"], df["yanlis"], bottom=df["dogru"], label="Yanlış", color="red")
@@ -125,7 +135,7 @@ def ogretmen_paneli(sifre):
125
 
126
  return "✅ Giriş başarılı", grafik_yolu
127
 
128
- # Gradio Arayüzü
129
  with gr.Blocks() as demo:
130
  gr.Markdown("## 📚 İngilizce Kelime Testi (15 Soru)")
131
 
@@ -135,28 +145,35 @@ with gr.Blocks() as demo:
135
 
136
  soru_kutusu = gr.Textbox(label="Soru", interactive=False, visible=False)
137
  ses_kutusu = gr.Audio(label="Kelimenin Telaffuzu", interactive=False, type="filepath")
138
- cevap_input = gr.Textbox(label="Türkçesini Yazınız")
139
- cevap_btn = gr.Button("Cevabı Kontrol Et")
140
  geribildirim = gr.Textbox(label="Geri Bildirim", interactive=False)
141
 
142
- cevap_input.visible = False
143
- cevap_btn.visible = False
144
- ses_kutusu.visible = False
145
-
146
- baslat_btn.click(baslat, inputs=isim_input,
147
- outputs=[soru_kutusu, isim_input, ses_kutusu, cevap_input, cevap_btn])
148
-
149
- cevap_btn.click(kontrol_et, inputs=cevap_input,
150
- outputs=[geribildirim, soru_kutusu, ses_kutusu, cevap_input, cevap_btn])
151
-
152
- # 👩‍🏫 Öğretmen Paneli
 
 
 
 
153
  with gr.Accordion("👩‍🏫 Öğretmen Girişi", open=False):
154
  sifre = gr.Textbox(label="Şifre", type="password")
155
  sifre_btn = gr.Button("Giriş Yap")
156
  sonuc_mesaj = gr.Textbox(label="Durum", interactive=False)
157
  grafik = gr.Image()
158
 
159
- sifre_btn.click(ogretmen_paneli, inputs=sifre, outputs=[sonuc_mesaj, grafik])
160
-
161
- demo.launch()
 
 
162
 
 
 
7
  import matplotlib.pyplot as plt
8
  from gtts import gTTS
9
 
10
+ # Geçici ses klasörü
11
  TEMP_SESLER_KLASORU = "temp_sesler"
12
  os.makedirs(TEMP_SESLER_KLASORU, exist_ok=True)
13
 
14
+ # Ses üretici fonksiyon
15
  def ses_uret(kelime):
16
  yol = f"{TEMP_SESLER_KLASORU}/{kelime}.mp3"
17
  if not os.path.exists(yol):
 
19
  tts.save(yol)
20
  return yol
21
 
22
+ # Kelimeleri yükle
23
  kelimeler = pd.read_csv("kelimeler.csv")
24
  kelimeler = kelimeler.sample(frac=1).reset_index(drop=True) # Karıştır
25
 
26
+ # Kullanıcı oturumu yönetimi
27
  user_session = {
28
  "isim": "",
29
  "soru_index": 0,
 
34
 
35
  SONUC_DOSYASI = "results.json"
36
 
37
+ # Soru getirme
 
 
 
 
 
 
 
 
 
38
  def get_soru():
39
  idx = user_session["soru_index"]
40
  if idx >= 15:
 
44
  ses_yolu = ses_uret(satir["english"])
45
  return f"{idx+1}. Kelime: {satir['english']}", ses_yolu, "", "", True
46
 
47
+ # Teste başlat
48
+ def baslat(isim):
49
+ user_session["isim"] = isim
50
+ user_session["soru_index"] = 0
51
+ user_session["dogru"] = 0
52
+ user_session["yanlis"] = 0
53
+ user_session["cevaplar"] = []
54
+
55
+ soru, ses, _, _, _ = get_soru()
56
+
57
+ return (
58
+ soru, # soru_kutusu
59
+ gr.update(visible=False),# isim_input
60
+ ses, # ses_kutusu
61
+ gr.update(visible=True), # cevap_input
62
+ gr.update(visible=True) # cevap_btn
63
+ )
64
+
65
+ # Cevap kontrol ve ilerleme
66
  def kontrol_et(turkce_cevap):
67
  idx = user_session["soru_index"]
68
  satir = kelimeler.iloc[idx]
 
86
  soru, ses, _, _, aktif = get_soru()
87
  return geribildirim, soru, ses, "", aktif
88
 
89
+ # Sonuçları JSON'a kaydet
90
  def kaydet_sonuc():
91
  sonuc = {
92
  "isim": user_session["isim"],
 
106
  with open(SONUC_DOSYASI, "w") as f:
107
  json.dump(veriler, f)
108
 
109
+ # Öğretmen paneli
110
  def ogretmen_paneli(sifre):
111
  if sifre != "5555":
112
  return "❌ Hatalı şifre", None
 
119
 
120
  df = pd.DataFrame(veriler)
121
 
122
+
123
+ # Grafik oluştur
124
  plt.figure(figsize=(6,4))
125
  plt.bar(df["isim"], df["dogru"], label="Doğru", color="green")
126
  plt.bar(df["isim"], df["yanlis"], bottom=df["dogru"], label="Yanlış", color="red")
 
135
 
136
  return "✅ Giriş başarılı", grafik_yolu
137
 
138
+ # Gradio Arayüzü
139
  with gr.Blocks() as demo:
140
  gr.Markdown("## 📚 İngilizce Kelime Testi (15 Soru)")
141
 
 
145
 
146
  soru_kutusu = gr.Textbox(label="Soru", interactive=False, visible=False)
147
  ses_kutusu = gr.Audio(label="Kelimenin Telaffuzu", interactive=False, type="filepath")
148
+ cevap_input = gr.Textbox(label="Türkçesini Yazınız", visible=False)
149
+ cevap_btn = gr.Button("Cevabı Kontrol Et", visible=False)
150
  geribildirim = gr.Textbox(label="Geri Bildirim", interactive=False)
151
 
152
+ # Başlat butonuna tıklanınca çalışır
153
+ baslat_btn.click(
154
+ baslat,
155
+ inputs=isim_input,
156
+ outputs=[soru_kutusu, isim_input, ses_kutusu, cevap_input, cevap_btn]
157
+ )
158
+
159
+ # Cevabı kontrol eder
160
+ cevap_btn.click(
161
+ kontrol_et,
162
+ inputs=cevap_input,
163
+ outputs=[geribildirim, soru_kutusu, ses_kutusu, cevap_input, cevap_btn]
164
+ )
165
+
166
+ # Öğretmen Paneli
167
  with gr.Accordion("👩‍🏫 Öğretmen Girişi", open=False):
168
  sifre = gr.Textbox(label="Şifre", type="password")
169
  sifre_btn = gr.Button("Giriş Yap")
170
  sonuc_mesaj = gr.Textbox(label="Durum", interactive=False)
171
  grafik = gr.Image()
172
 
173
+ sifre_btn.click(
174
+ ogretmen_paneli,
175
+ inputs=sifre,
176
+ outputs=[sonuc_mesaj, grafik]
177
+ )
178
 
179
+ demo.launch()