aliicemill commited on
Commit
6bc66b8
·
verified ·
1 Parent(s): 259076d

Update app.py

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