aliicemill commited on
Commit
2f0b116
·
verified ·
1 Parent(s): 06dc014

Delete app.py

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