Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,542 +1,545 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import re
|
3 |
-
import numpy as np
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
from io import BytesIO
|
6 |
-
|
7 |
-
def run_turkish():
|
8 |
-
# Başlık
|
9 |
-
st.title("Note Analyzer Streamlit Uygulaması")
|
10 |
-
|
11 |
-
# Uygulamanın çalışma prensibi görüntüleme durumu
|
12 |
-
if "show_images" not in st.session_state:
|
13 |
-
st.session_state.show_images = True # Varsayılan olarak resimler gösterilsin
|
14 |
-
|
15 |
-
# Kullanıcıdan veri alma (Sidebar sabit kalıyor)
|
16 |
-
st.sidebar.header("Girdi Alanları")
|
17 |
-
|
18 |
-
# Dosya yükleme veya metin girişi seçimi
|
19 |
-
input_method = st.sidebar.radio(
|
20 |
-
"Notları nasıl gireceksiniz?",
|
21 |
-
options=["Dosya Yükle", "Kopyala-Yapıştır"]
|
22 |
-
)
|
23 |
-
|
24 |
-
uploaded_file = None
|
25 |
-
text_input = None
|
26 |
-
|
27 |
-
if input_method == "Dosya Yükle":
|
28 |
-
uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"])
|
29 |
-
elif input_method == "Kopyala-Yapıştır":
|
30 |
-
text_input = st.sidebar.text_area("Notları Yapıştırın", height=200)
|
31 |
-
|
32 |
-
# Diğer parametreler
|
33 |
-
lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
|
34 |
-
perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
|
35 |
-
my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
|
36 |
-
note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1)
|
37 |
-
amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1)
|
38 |
-
first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
|
39 |
-
increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
|
40 |
-
|
41 |
-
if st.sidebar.button("Analizi Çalıştır"):
|
42 |
-
# Butona basıldığında resimleri gizle
|
43 |
-
st.session_state.show_images = False
|
44 |
-
|
45 |
-
# Resimler yalnızca show_images True ise gösterilir
|
46 |
-
if st.session_state.show_images:
|
47 |
-
st.subheader("Uygulamanın Çalışma Prensibi")
|
48 |
-
|
49 |
-
# Resimlerin dosya isimlerini sırayla listele
|
50 |
-
image_files = ["turkish/a.png", "turkish/b.png", "turkish/c.png", "turkish/d.png"]
|
51 |
-
|
52 |
-
# Resimleri alt alta ekle
|
53 |
-
for image_file in image_files:
|
54 |
-
st.image(image_file, use_container_width=True)
|
55 |
-
|
56 |
-
# Notları yükleme ve işleme işlemleri (Butona basıldıysa çalışır)
|
57 |
-
if not st.session_state.show_images:
|
58 |
-
if input_method == "Dosya Yükle" and uploaded_file is None:
|
59 |
-
st.error("Lütfen bir dosya yükleyin!")
|
60 |
-
elif input_method == "Kopyala-Yapıştır" and not text_input:
|
61 |
-
st.error("Lütfen notları metin kutusuna yapıştırın!")
|
62 |
-
else:
|
63 |
-
try:
|
64 |
-
# Dosya veya metin kutusundan içerik okuma
|
65 |
-
if uploaded_file:
|
66 |
-
content = uploaded_file.read().decode("utf-8")
|
67 |
-
elif text_input:
|
68 |
-
content = text_input
|
69 |
-
|
70 |
-
# Veriyi işleme
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
notes_result =
|
76 |
-
notes_result =
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
st.
|
88 |
-
st.write(f"
|
89 |
-
st.write(f"En
|
90 |
-
st.write(f"
|
91 |
-
st.write(f"
|
92 |
-
st.write(f"
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
plt.
|
100 |
-
plt.
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
plt.
|
111 |
-
plt.
|
112 |
-
plt.
|
113 |
-
plt.
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
f"
|
119 |
-
f"En
|
120 |
-
f"
|
121 |
-
f"
|
122 |
-
f"
|
123 |
-
f"
|
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 |
-
st.
|
167 |
-
st.write("
|
168 |
-
st.write("
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
notes_result =
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
st.
|
260 |
-
st.write(f"
|
261 |
-
st.write(f"
|
262 |
-
st.write(f"
|
263 |
-
st.write(f"
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
plt.
|
271 |
-
plt.
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
plt.
|
283 |
-
plt.
|
284 |
-
plt.
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
f"
|
291 |
-
f"
|
292 |
-
f"
|
293 |
-
f"
|
294 |
-
f"
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
plt.
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
buf
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
st.
|
337 |
-
st.write("
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
st.error("Please
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
content =
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
st.
|
430 |
-
st.write(f"
|
431 |
-
st.write(f"
|
432 |
-
st.write(f"
|
433 |
-
|
434 |
-
|
435 |
-
st.
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
plt.
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
plt.
|
453 |
-
plt.
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
f"
|
461 |
-
f"
|
462 |
-
f"
|
463 |
-
f"
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
#
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
st.
|
508 |
-
|
509 |
-
|
510 |
-
st.
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
""
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
with
|
529 |
-
if st.button("
|
530 |
-
st.session_state.language = "
|
531 |
-
with
|
532 |
-
if st.button("
|
533 |
-
st.session_state.language = "
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import re
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
def run_turkish():
|
8 |
+
# Başlık
|
9 |
+
st.title("Note Analyzer Streamlit Uygulaması")
|
10 |
+
|
11 |
+
# Uygulamanın çalışma prensibi görüntüleme durumu
|
12 |
+
if "show_images" not in st.session_state:
|
13 |
+
st.session_state.show_images = True # Varsayılan olarak resimler gösterilsin
|
14 |
+
|
15 |
+
# Kullanıcıdan veri alma (Sidebar sabit kalıyor)
|
16 |
+
st.sidebar.header("Girdi Alanları")
|
17 |
+
|
18 |
+
# Dosya yükleme veya metin girişi seçimi
|
19 |
+
input_method = st.sidebar.radio(
|
20 |
+
"Notları nasıl gireceksiniz?",
|
21 |
+
options=["Dosya Yükle", "Kopyala-Yapıştır"]
|
22 |
+
)
|
23 |
+
|
24 |
+
uploaded_file = None
|
25 |
+
text_input = None
|
26 |
+
|
27 |
+
if input_method == "Dosya Yükle":
|
28 |
+
uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"])
|
29 |
+
elif input_method == "Kopyala-Yapıştır":
|
30 |
+
text_input = st.sidebar.text_area("Notları Yapıştırın", height=200)
|
31 |
+
|
32 |
+
# Diğer parametreler
|
33 |
+
lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı")
|
34 |
+
perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1)
|
35 |
+
my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1)
|
36 |
+
note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1)
|
37 |
+
amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1)
|
38 |
+
first_step = st.sidebar.number_input("İlk Adım", value=0, step=1)
|
39 |
+
increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1)
|
40 |
+
|
41 |
+
if st.sidebar.button("Analizi Çalıştır"):
|
42 |
+
# Butona basıldığında resimleri gizle
|
43 |
+
st.session_state.show_images = False
|
44 |
+
|
45 |
+
# Resimler yalnızca show_images True ise gösterilir
|
46 |
+
if st.session_state.show_images:
|
47 |
+
st.subheader("Uygulamanın Çalışma Prensibi")
|
48 |
+
|
49 |
+
# Resimlerin dosya isimlerini sırayla listele
|
50 |
+
image_files = ["turkish/a.png", "turkish/b.png", "turkish/c.png", "turkish/d.png"]
|
51 |
+
|
52 |
+
# Resimleri alt alta ekle
|
53 |
+
for image_file in image_files:
|
54 |
+
st.image(image_file, use_container_width=True)
|
55 |
+
|
56 |
+
# Notları yükleme ve işleme işlemleri (Butona basıldıysa çalışır)
|
57 |
+
if not st.session_state.show_images:
|
58 |
+
if input_method == "Dosya Yükle" and uploaded_file is None:
|
59 |
+
st.error("Lütfen bir dosya yükleyin!")
|
60 |
+
elif input_method == "Kopyala-Yapıştır" and not text_input:
|
61 |
+
st.error("Lütfen notları metin kutusuna yapıştırın!")
|
62 |
+
else:
|
63 |
+
try:
|
64 |
+
# Dosya veya metin kutusundan içerik okuma
|
65 |
+
if uploaded_file:
|
66 |
+
content = uploaded_file.read().decode("utf-8")
|
67 |
+
elif text_input:
|
68 |
+
content = text_input
|
69 |
+
|
70 |
+
# Veriyi işleme
|
71 |
+
content = content.strip()
|
72 |
+
result = re.split(r'[ \n]+', content)
|
73 |
+
|
74 |
+
# Strip fonksiyonu ve kaçış dizisi temizliği
|
75 |
+
notes_result = [x.strip() for x in result[first_step::increase_amount] if x.strip() != '∅' and x.strip() != "NA"]
|
76 |
+
notes_result = list(map(lambda x: float(x), notes_result))
|
77 |
+
notes_result = np.array(notes_result)
|
78 |
+
|
79 |
+
# İstatistikler
|
80 |
+
average_x = np.average(notes_result)
|
81 |
+
min_x = notes_result.min()
|
82 |
+
max_x = notes_result.max()
|
83 |
+
std = np.std(notes_result)
|
84 |
+
z_score = (my_note - average_x) / std
|
85 |
+
|
86 |
+
# İstatistikleri ekrana yazdırma
|
87 |
+
st.subheader("Genel Bilgiler")
|
88 |
+
st.write(f"Katilimci Sayısı: {len(notes_result)}")
|
89 |
+
st.write(f"En Düşük Not: {min_x:.2f}")
|
90 |
+
st.write(f"En Yüksek Not: {max_x:.2f}")
|
91 |
+
st.write(f"Ortalama Not: {average_x:.2f}")
|
92 |
+
st.write(f"Standart Sapma: {std:.2f}")
|
93 |
+
st.write(f"Z-Skoru: {z_score:.2f}")
|
94 |
+
|
95 |
+
# Grafik oluşturma
|
96 |
+
st.subheader("Not Dağılım Grafiği")
|
97 |
+
unique_values, counts = np.unique(notes_result, return_counts=True)
|
98 |
+
plt.figure(figsize=(10, 6))
|
99 |
+
bars = plt.bar(unique_values, counts, width=0.3)
|
100 |
+
plt.axvline(x=average_x, color='red', linestyle='--')
|
101 |
+
plt.text(average_x + 1.5, max(counts), 'Ortalama Not', color='red', rotation=0, ha='center', va='bottom')
|
102 |
+
|
103 |
+
if my_note in unique_values:
|
104 |
+
plt.text(my_note, counts[unique_values == my_note][0], 'Benim\nNotum', color='green', rotation=0, ha='center', va='bottom')
|
105 |
+
|
106 |
+
for bar in bars:
|
107 |
+
if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
|
108 |
+
bar.set_color('green')
|
109 |
+
|
110 |
+
plt.title(f'{lecture_name} Not Sayıları Grafiği')
|
111 |
+
plt.xlabel('Notlar')
|
112 |
+
plt.ylabel('Adet')
|
113 |
+
plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
|
114 |
+
plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
|
115 |
+
|
116 |
+
# Grafik bilgileri
|
117 |
+
info_text = (
|
118 |
+
f"Katilimci sayısı: {len(notes_result)}\n"
|
119 |
+
f"En düşük not: {min_x:.2f}\n"
|
120 |
+
f"En yüksek not: {max_x:.2f}\n"
|
121 |
+
f"Benim notum: {my_note:.2f}\n"
|
122 |
+
f"Ortalama not: {average_x:.2f}\n"
|
123 |
+
f"Standart sapma: {std:.2f}\n"
|
124 |
+
f"Z-skoru: {z_score:.2f}"
|
125 |
+
)
|
126 |
+
plt.text(
|
127 |
+
1.05 * max(unique_values), 0.8 * max(counts),
|
128 |
+
info_text,
|
129 |
+
fontsize=10,
|
130 |
+
color="black",
|
131 |
+
ha="left",
|
132 |
+
va="top",
|
133 |
+
bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
|
134 |
+
)
|
135 |
+
plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
|
136 |
+
|
137 |
+
# Sağ alt köşeye "Generated by Note Analyzer" metni ekle
|
138 |
+
plt.text(
|
139 |
+
0.99, -0.15, # Sağ alt köşeye konumlandır
|
140 |
+
"Generated by Note Analyzer at HuggingFace aliicemill/NoteAnalyzer space",
|
141 |
+
fontsize=8,
|
142 |
+
color="gray",
|
143 |
+
ha="right",
|
144 |
+
va="top",
|
145 |
+
transform=plt.gca().transAxes # Koordinatları grafiğe göre ayarla
|
146 |
+
)
|
147 |
+
|
148 |
+
# Grafik gösterimi
|
149 |
+
st.pyplot(plt)
|
150 |
+
|
151 |
+
# Grafik indirme bağlantısı
|
152 |
+
buf = BytesIO()
|
153 |
+
plt.savefig(buf, format="png")
|
154 |
+
buf.seek(0)
|
155 |
+
st.download_button(
|
156 |
+
label="Grafiği İndir",
|
157 |
+
data=buf,
|
158 |
+
file_name="not_dagilimi.png",
|
159 |
+
mime="image/png"
|
160 |
+
)
|
161 |
+
|
162 |
+
except Exception as e:
|
163 |
+
st.error(f"Hata: {e}")
|
164 |
+
|
165 |
+
# Web sayfasının altına isim ve tarih
|
166 |
+
st.markdown("---")
|
167 |
+
st.write("Developed by: Ali Cemil Özdemir")
|
168 |
+
st.write("Date: 01.12.2024")
|
169 |
+
st.write("For feedback and suggestions, you can contact me at [email protected]")
|
170 |
+
|
171 |
+
# Grafiklerin sağ alt köşesine yazı ekleme
|
172 |
+
st.markdown("""
|
173 |
+
<p style="position:absolute; bottom:0px; right:0px; font-size: 12px; color: gray;">
|
174 |
+
Created with Note Analyzer
|
175 |
+
</p>
|
176 |
+
""", unsafe_allow_html=True)
|
177 |
+
|
178 |
+
|
179 |
+
def run_arabic():
|
180 |
+
# العنوان
|
181 |
+
st.title("تطبيق محلل الدرجات باستخدام Streamlit")
|
182 |
+
|
183 |
+
# حالة عرض الصور
|
184 |
+
if "show_images" not in st.session_state:
|
185 |
+
st.session_state.show_images = True # الافتراضي: يتم عرض الصور
|
186 |
+
|
187 |
+
# منطقة إدخال البيانات في الشريط الجانبي
|
188 |
+
st.sidebar.header("حقول الإدخال")
|
189 |
+
|
190 |
+
# اختيار رفع ملف أو إدخال النصوص يدويًا
|
191 |
+
input_method = st.sidebar.radio(
|
192 |
+
"كيف ستقدم الدرجات؟",
|
193 |
+
options=["رفع ملف", "نسخ ولصق"]
|
194 |
+
)
|
195 |
+
|
196 |
+
uploaded_file = None
|
197 |
+
text_input = None
|
198 |
+
|
199 |
+
if input_method == "رفع ملف":
|
200 |
+
uploaded_file = st.sidebar.file_uploader("قم برفع ملف الدرجات (TXT)", type=["txt"])
|
201 |
+
elif input_method == "نسخ ولصق":
|
202 |
+
text_input = st.sidebar.text_area("قم بلصق الدرجات هنا", height=200)
|
203 |
+
|
204 |
+
# المعلمات الأخرى
|
205 |
+
lecture_name = st.sidebar.text_input("اسم المادة", value="اسم المادة")
|
206 |
+
perfect_score = st.sidebar.number_input("الدرجة الكاملة", value=100, step=1)
|
207 |
+
my_note = st.sidebar.number_input("درجتي", value=0.0, step=0.1)
|
208 |
+
note_s_axis_diff = st.sidebar.number_input("حجم خطوات المحور السيني للدرجات", value=5, step=1)
|
209 |
+
amount_s_axis_diff = st.sidebar.number_input("حجم خطوات المحور الصادي للتكرار", value=1, step=1)
|
210 |
+
first_step = st.sidebar.number_input("الخطوة الأولى", value=0, step=1)
|
211 |
+
increase_amount = st.sidebar.number_input("مقدار الزيادة", value=1, step=1)
|
212 |
+
|
213 |
+
if st.sidebar.button("تشغيل التحليل"):
|
214 |
+
# إخفاء الصور عند النقر على الزر
|
215 |
+
st.session_state.show_images = False
|
216 |
+
|
217 |
+
# عرض الصور فقط إذا كانت show_images صحيحة
|
218 |
+
if st.session_state.show_images:
|
219 |
+
st.subheader("كيفية عمل التطبيق")
|
220 |
+
|
221 |
+
# قائمة بأسماء ملفات الصور بالترتيب
|
222 |
+
image_files = ["arabic/a.png", "arabic/b.png", "arabic/c.png", "arabic/d.png"]
|
223 |
+
|
224 |
+
# عرض الصور واحدة تحت الأخرى
|
225 |
+
for image_file in image_files:
|
226 |
+
st.image(image_file, use_container_width=True)
|
227 |
+
|
228 |
+
# تحميل ومعالجة الدرجات (يعمل فقط إذا تم النقر على الزر)
|
229 |
+
if not st.session_state.show_images:
|
230 |
+
if input_method == "رفع ملف" and uploaded_file is None:
|
231 |
+
st.error("يرجى رفع ملف!")
|
232 |
+
elif input_method == "نسخ ولصق" and not text_input:
|
233 |
+
st.error("يرجى لصق الدرجات في مربع النص!")
|
234 |
+
else:
|
235 |
+
try:
|
236 |
+
# قراءة المحتوى من الملف أو مربع النص
|
237 |
+
if uploaded_file:
|
238 |
+
content = uploaded_file.read().decode("utf-8")
|
239 |
+
elif text_input:
|
240 |
+
content = text_input
|
241 |
+
|
242 |
+
# معالجة البيانات
|
243 |
+
content = content.strip()
|
244 |
+
result = re.split(r'[ \n]+', content)
|
245 |
+
|
246 |
+
# تنظيف وتصنيف البيانات
|
247 |
+
notes_result = [x.strip() for x in result[first_step::increase_amount] if x.strip() != '∅' and x.strip() != "NA"]
|
248 |
+
notes_result = list(map(lambda x: float(x), notes_result))
|
249 |
+
notes_result = np.array(notes_result)
|
250 |
+
|
251 |
+
# الإحصائيات
|
252 |
+
average_x = np.average(notes_result)
|
253 |
+
min_x = notes_result.min()
|
254 |
+
max_x = notes_result.max()
|
255 |
+
std = np.std(notes_result)
|
256 |
+
z_score = (my_note - average_x) / std
|
257 |
+
|
258 |
+
# عرض الإحصائيات
|
259 |
+
st.subheader("المعلومات العامة")
|
260 |
+
st.write(f"عدد المشاركين: {len(notes_result)}")
|
261 |
+
st.write(f"أقل درجة: {min_x:.2f}")
|
262 |
+
st.write(f"أعلى درجة: {max_x:.2f}")
|
263 |
+
st.write(f"متوسط الدرجات: {average_x:.2f}")
|
264 |
+
st.write(f"الانحراف المعياري: {std:.2f}")
|
265 |
+
st.write(f"درجة Z: {z_score:.2f}")
|
266 |
+
|
267 |
+
# إنشاء الرسم البياني
|
268 |
+
st.subheader("رسم توزيع الدرجات")
|
269 |
+
unique_values, counts = np.unique(notes_result, return_counts=True)
|
270 |
+
plt.figure(figsize=(10, 6))
|
271 |
+
bars = plt.bar(unique_values, counts, width=0.3)
|
272 |
+
plt.axvline(x=average_x, color='red', linestyle='--')
|
273 |
+
plt.text(average_x + 1.5, max(counts), 'متوسط الدرجات', color='red', rotation=0, ha='center', va='bottom')
|
274 |
+
|
275 |
+
if my_note in unique_values:
|
276 |
+
plt.text(my_note, counts[unique_values == my_note][0], 'درجتي', color='green', rotation=0, ha='center', va='bottom')
|
277 |
+
|
278 |
+
for bar in bars:
|
279 |
+
if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
|
280 |
+
bar.set_color('green')
|
281 |
+
|
282 |
+
plt.title(f'رسم توزيع الدرجات لمادة {lecture_name}')
|
283 |
+
plt.xlabel('الدرجات')
|
284 |
+
plt.ylabel('التكرار')
|
285 |
+
plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
|
286 |
+
plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
|
287 |
+
|
288 |
+
# إضافة معلومات إلى الرسم البياني
|
289 |
+
info_text = (
|
290 |
+
f"عدد المشاركين: {len(notes_result)}\n"
|
291 |
+
f"أقل درجة: {min_x:.2f}\n"
|
292 |
+
f"أعلى درجة: {max_x:.2f}\n"
|
293 |
+
f"درجتي: {my_note:.2f}\n"
|
294 |
+
f"متوسط الدرجات: {average_x:.2f}\n"
|
295 |
+
f"الانحراف المعياري: {std:.2f}\n"
|
296 |
+
f"درجة Z: {z_score:.2f}"
|
297 |
+
)
|
298 |
+
plt.text(
|
299 |
+
1.05 * max(unique_values), 0.8 * max(counts),
|
300 |
+
info_text,
|
301 |
+
fontsize=10,
|
302 |
+
color="black",
|
303 |
+
ha="left",
|
304 |
+
va="top",
|
305 |
+
bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
|
306 |
+
)
|
307 |
+
plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
|
308 |
+
# Sağ alt köşeye "Generated by Note Analyzer" metni ekle
|
309 |
+
plt.text(
|
310 |
+
0.99, -0.15, # Sağ alt köşeye konumlandır
|
311 |
+
"Generated by Note Analyzer at HuggingFace aliicemill/NoteAnalyzer space",
|
312 |
+
fontsize=8,
|
313 |
+
color="gray",
|
314 |
+
ha="right",
|
315 |
+
va="top",
|
316 |
+
transform=plt.gca().transAxes # Koordinatları grafiğe göre ayarla
|
317 |
+
)
|
318 |
+
# عرض الرسم البياني
|
319 |
+
st.pyplot(plt)
|
320 |
+
|
321 |
+
# زر لتحميل الرسم البياني
|
322 |
+
buf = BytesIO()
|
323 |
+
plt.savefig(buf, format="png")
|
324 |
+
buf.seek(0)
|
325 |
+
st.download_button(
|
326 |
+
label="تحميل الرسم البياني",
|
327 |
+
data=buf,
|
328 |
+
file_name="score_distribution.png",
|
329 |
+
mime="image/png"
|
330 |
+
)
|
331 |
+
|
332 |
+
except Exception as e:
|
333 |
+
st.error(f"خطأ: {e}")
|
334 |
+
|
335 |
+
# التذييل
|
336 |
+
st.markdown("---")
|
337 |
+
st.write("تم التطوير بواسطة: علي جميل أوزدمير")
|
338 |
+
st.write("التاريخ: 01.12.2024")
|
339 |
+
st.write("للتعليقات والاقتراحات، يمكنك التواصل عبر: [email protected]")
|
340 |
+
|
341 |
+
# إضافة ملاحظة أسفل الزاوية اليمنى
|
342 |
+
st.markdown("""
|
343 |
+
<p style="position:absolute; bottom:0px; right:0px; font-size: 12px; color: gray;">
|
344 |
+
تم الإنشاء باستخد��م محلل الدرجات
|
345 |
+
</p>
|
346 |
+
""", unsafe_allow_html=True)
|
347 |
+
|
348 |
+
|
349 |
+
def run_english():
|
350 |
+
# Title
|
351 |
+
st.title("Note Analyzer Streamlit Application")
|
352 |
+
|
353 |
+
# Image display state
|
354 |
+
if "show_images" not in st.session_state:
|
355 |
+
st.session_state.show_images = True # Default: images are shown
|
356 |
+
|
357 |
+
# Sidebar input area
|
358 |
+
st.sidebar.header("Input Fields")
|
359 |
+
|
360 |
+
# File upload or text input selection
|
361 |
+
input_method = st.sidebar.radio(
|
362 |
+
"How will you provide the notes?",
|
363 |
+
options=["Upload File", "Copy-Paste"]
|
364 |
+
)
|
365 |
+
|
366 |
+
uploaded_file = None
|
367 |
+
text_input = None
|
368 |
+
|
369 |
+
if input_method == "Upload File":
|
370 |
+
uploaded_file = st.sidebar.file_uploader("Upload the Notes File (TXT)", type=["txt"])
|
371 |
+
elif input_method == "Copy-Paste":
|
372 |
+
text_input = st.sidebar.text_area("Paste the Notes Here", height=200)
|
373 |
+
|
374 |
+
# Other parameters
|
375 |
+
lecture_name = st.sidebar.text_input("Course Name", value="Course Name")
|
376 |
+
perfect_score = st.sidebar.number_input("Maximum Exam Score", value=100, step=1)
|
377 |
+
my_note = st.sidebar.number_input("My Score", value=0.0, step=0.1)
|
378 |
+
note_s_axis_diff = st.sidebar.number_input("Score X-Axis Step Size", value=5, step=1)
|
379 |
+
amount_s_axis_diff = st.sidebar.number_input("Frequency Y-Axis Step Size", value=1, step=1)
|
380 |
+
first_step = st.sidebar.number_input("First Step", value=0, step=1)
|
381 |
+
increase_amount = st.sidebar.number_input("Step Increase", value=1, step=1)
|
382 |
+
|
383 |
+
if st.sidebar.button("Run Analysis"):
|
384 |
+
# Hide images when the button is clicked
|
385 |
+
st.session_state.show_images = False
|
386 |
+
|
387 |
+
# Show images only if show_images is True
|
388 |
+
if st.session_state.show_images:
|
389 |
+
st.subheader("How the Application Works")
|
390 |
+
|
391 |
+
# List the image filenames in order
|
392 |
+
image_files = ["english/a.png", "english/b.png", "english/c.png", "english/d.png"]
|
393 |
+
|
394 |
+
# Display images one below the other
|
395 |
+
for image_file in image_files:
|
396 |
+
st.image(image_file, use_container_width=True)
|
397 |
+
|
398 |
+
# Load and process notes (Only works if the button is clicked)
|
399 |
+
if not st.session_state.show_images:
|
400 |
+
if input_method == "Upload File" and uploaded_file is None:
|
401 |
+
st.error("Please upload a file!")
|
402 |
+
elif input_method == "Copy-Paste" and not text_input:
|
403 |
+
st.error("Please paste the notes into the text area!")
|
404 |
+
else:
|
405 |
+
try:
|
406 |
+
# Read content from file or text area
|
407 |
+
if uploaded_file:
|
408 |
+
content = uploaded_file.read().decode("utf-8")
|
409 |
+
elif text_input:
|
410 |
+
content = text_input
|
411 |
+
|
412 |
+
# Process the data
|
413 |
+
content = content.strip()
|
414 |
+
result = re.split(r'[ \n]+', content)
|
415 |
+
|
416 |
+
# Clean and filter the data
|
417 |
+
notes_result = [x.strip() for x in result[first_step::increase_amount] if x.strip() != '∅' and x.strip() != "NA"]
|
418 |
+
notes_result = list(map(lambda x: float(x), notes_result))
|
419 |
+
notes_result = np.array(notes_result)
|
420 |
+
|
421 |
+
# Statistics
|
422 |
+
average_x = np.average(notes_result)
|
423 |
+
min_x = notes_result.min()
|
424 |
+
max_x = notes_result.max()
|
425 |
+
std = np.std(notes_result)
|
426 |
+
z_score = (my_note - average_x) / std
|
427 |
+
|
428 |
+
# Display statistics
|
429 |
+
st.subheader("General Information")
|
430 |
+
st.write(f"Number of Participants: {len(notes_result)}")
|
431 |
+
st.write(f"Lowest Score: {min_x:.2f}")
|
432 |
+
st.write(f"Highest Score: {max_x:.2f}")
|
433 |
+
st.write(f"Average Score: {average_x:.2f}")
|
434 |
+
st.write(f"Standard Deviation: {std:.2f}")
|
435 |
+
st.write(f"Z-Score: {z_score:.2f}")
|
436 |
+
|
437 |
+
# Create plot
|
438 |
+
st.subheader("Score Distribution Graph")
|
439 |
+
unique_values, counts = np.unique(notes_result, return_counts=True)
|
440 |
+
plt.figure(figsize=(10, 6))
|
441 |
+
bars = plt.bar(unique_values, counts, width=0.3)
|
442 |
+
plt.axvline(x=average_x, color='red', linestyle='--')
|
443 |
+
plt.text(average_x + 1.5, max(counts), 'Average Score', color='red', rotation=0, ha='center', va='bottom')
|
444 |
+
|
445 |
+
if my_note in unique_values:
|
446 |
+
plt.text(my_note, counts[unique_values == my_note][0], 'My\nScore', color='green', rotation=0, ha='center', va='bottom')
|
447 |
+
|
448 |
+
for bar in bars:
|
449 |
+
if bar.get_x() <= my_note < bar.get_x() + bar.get_width():
|
450 |
+
bar.set_color('green')
|
451 |
+
|
452 |
+
plt.title(f'{lecture_name} Score Distribution')
|
453 |
+
plt.xlabel('Scores')
|
454 |
+
plt.ylabel('Count')
|
455 |
+
plt.xticks(range(0, int(perfect_score), note_s_axis_diff), rotation=90)
|
456 |
+
plt.yticks(range(0, max(counts), amount_s_axis_diff), rotation=0)
|
457 |
+
|
458 |
+
# Add graph information
|
459 |
+
info_text = (
|
460 |
+
f"Number of participants: {len(notes_result)}\n"
|
461 |
+
f"Lowest score: {min_x:.2f}\n"
|
462 |
+
f"Highest score: {max_x:.2f}\n"
|
463 |
+
f"My score: {my_note:.2f}\n"
|
464 |
+
f"Average score: {average_x:.2f}\n"
|
465 |
+
f"Standard deviation: {std:.2f}\n"
|
466 |
+
f"Z-score: {z_score:.2f}"
|
467 |
+
)
|
468 |
+
plt.text(
|
469 |
+
1.05 * max(unique_values), 0.8 * max(counts),
|
470 |
+
info_text,
|
471 |
+
fontsize=10,
|
472 |
+
color="black",
|
473 |
+
ha="left",
|
474 |
+
va="top",
|
475 |
+
bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey")
|
476 |
+
)
|
477 |
+
plt.subplots_adjust(left=0.055, bottom=0.065, right=0.90, top=0.962, wspace=0.2, hspace=0.2)
|
478 |
+
# Sağ alt köşeye "Generated by Note Analyzer" metni ekle
|
479 |
+
plt.text(
|
480 |
+
0.99, -0.15, # Sağ alt köşeye konumlandır
|
481 |
+
"Generated by Note Analyzer at HuggingFace aliicemill/NoteAnalyzer space",
|
482 |
+
fontsize=8,
|
483 |
+
color="gray",
|
484 |
+
ha="right",
|
485 |
+
va="top",
|
486 |
+
transform=plt.gca().transAxes # Koordinatları grafiğe göre ayarla
|
487 |
+
)
|
488 |
+
|
489 |
+
# Display the plot
|
490 |
+
st.pyplot(plt)
|
491 |
+
|
492 |
+
# Download button for the plot
|
493 |
+
buf = BytesIO()
|
494 |
+
plt.savefig(buf, format="png")
|
495 |
+
buf.seek(0)
|
496 |
+
st.download_button(
|
497 |
+
label="Download Graph",
|
498 |
+
data=buf,
|
499 |
+
file_name="score_distribution.png",
|
500 |
+
mime="image/png"
|
501 |
+
)
|
502 |
+
|
503 |
+
except Exception as e:
|
504 |
+
st.error(f"Error: {e}")
|
505 |
+
|
506 |
+
# Footer
|
507 |
+
st.markdown("---")
|
508 |
+
st.write("Developed by: Ali Cemil Özdemir")
|
509 |
+
st.write("Date: 01.12.2024")
|
510 |
+
st.write("For feedback and suggestions, you can contact me at [email protected]")
|
511 |
+
|
512 |
+
# Add a note at the bottom right corner of the page
|
513 |
+
st.markdown("""
|
514 |
+
<p style="position:absolute; bottom:0px; right:0px; font-size: 12px; color: gray;">
|
515 |
+
Created with Note Analyzer
|
516 |
+
</p>
|
517 |
+
""", unsafe_allow_html=True)
|
518 |
+
|
519 |
+
# Session State'i başlat
|
520 |
+
if "language" not in st.session_state:
|
521 |
+
st.session_state.language = None
|
522 |
+
|
523 |
+
# Dil seçimi ekranı
|
524 |
+
if st.session_state.language is None:
|
525 |
+
st.title("Select language / Dili seçin / اختر اللغة")
|
526 |
+
col1, col2, col3 = st.columns(3)
|
527 |
+
|
528 |
+
with col1:
|
529 |
+
if st.button("Türkçe"):
|
530 |
+
st.session_state.language = "turkish"
|
531 |
+
with col2:
|
532 |
+
if st.button("English"):
|
533 |
+
st.session_state.language = "english"
|
534 |
+
with col3:
|
535 |
+
if st.button("عربي"):
|
536 |
+
st.session_state.language = "arabic"
|
537 |
+
|
538 |
+
# Seçilen dilin programını çalıştır
|
539 |
+
else:
|
540 |
+
if st.session_state.language == "turkish":
|
541 |
+
run_turkish()
|
542 |
+
elif st.session_state.language == "english":
|
543 |
+
run_english()
|
544 |
+
elif st.session_state.language == "arabic":
|
545 |
+
run_arabic()
|