Spaces:
Sleeping
Sleeping
| import re | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from io import BytesIO | |
| import streamlit as st | |
| import os | |
| # Dil Seçimi | |
| language = st.selectbox("Select Language / اختر اللغة / Seçiniz", ["Türkçe", "English", "عربي"]) | |
| # Dil Desteği İçin Metinler | |
| if language == "Türkçe": | |
| title_text = "Not Analyzer Streamlit Uygulaması" | |
| subheader_text = "Uygulamanın Çalışma Prensibi" | |
| error_message = "Lütfen bir dosya yükleyin!" if input_method == "Dosya Yükle" else "Lütfen notları metin kutusuna yapıştırın!" | |
| participant_text = "Katilimci Sayısı" | |
| min_text = "En Düşük Not" | |
| max_text = "En Yüksek Not" | |
| avg_text = "Ortalama Not" | |
| std_dev_text = "Standart Sapma" | |
| z_score_text = "Z-Skoru" | |
| download_text = "Grafiği İndir" | |
| info_text_header = "Genel Bilgiler" | |
| chart_title = "{lecture_name} Not Sayıları Grafiği" | |
| xlabel = "Notlar" | |
| ylabel = "Adet" | |
| elif language == "English": | |
| title_text = "Note Analyzer Streamlit Application" | |
| subheader_text = "How the Application Works" | |
| error_message = "Please upload a file!" if input_method == "Upload File" else "Please paste the notes in the text box!" | |
| participant_text = "Number of Participants" | |
| min_text = "Lowest Grade" | |
| max_text = "Highest Grade" | |
| avg_text = "Average Grade" | |
| std_dev_text = "Standard Deviation" | |
| z_score_text = "Z-Score" | |
| download_text = "Download Graph" | |
| info_text_header = "General Information" | |
| chart_title = "{lecture_name} Grade Distribution Graph" | |
| xlabel = "Grades" | |
| ylabel = "Count" | |
| else: # Arabic | |
| title_text = "تطبيق تحليل الدرجات" | |
| subheader_text = "مبدأ عمل التطبيق" | |
| error_message = "من فضلك حمّل ملفًا!" if input_method == "تحميل الملف" else "من فضلك الصق الملاحظات في مربع النص!" | |
| participant_text = "عدد المشاركين" | |
| min_text = "أدنى درجة" | |
| max_text = "أعلى درجة" | |
| avg_text = "متوسط الدرجة" | |
| std_dev_text = "الانحراف المعياري" | |
| z_score_text = "الدرجة Z" | |
| download_text = "تنزيل الرسم البياني" | |
| info_text_header = "المعلومات العامة" | |
| chart_title = "{lecture_name} الرسم البياني لتوزيع الدرجات" | |
| xlabel = "الدرجات" | |
| ylabel = "العدد" | |
| # Resim Dosya Yolları | |
| image_folder = language.lower() # dilin ismini küçük harf ile alıyoruz (örn: "english", "arabic", "turkish") | |
| image_files = [f"{image_folder}/{ch}.png" for ch in ['a', 'b', 'c', 'd', 'e', 'f', 'g']] | |
| # Başlık | |
| st.title(title_text) | |
| # Açıklama Resimleri | |
| st.subheader(subheader_text) | |
| # Resimleri alt alta ekle | |
| for image_file in image_files: | |
| if os.path.exists(image_file): | |
| st.image(image_file, use_container_width=True) # Yeni parametre kullanıldı | |
| # Kullanıcıdan veri alma (Sidebar sabit kalıyor) | |
| st.sidebar.header("Girdi Alanları") | |
| # Dosya yükleme veya metin girişi seçimi | |
| input_method = st.sidebar.radio("Notları nasıl gireceksiniz?", options=["Dosya Yükle", "Kopyala-Yapıştır"]) | |
| uploaded_file = None | |
| text_input = None | |
| if input_method == "Dosya Yükle": | |
| uploaded_file = st.sidebar.file_uploader("Notlar Dosyasını Yükleyin (TXT)", type=["txt"]) | |
| elif input_method == "Kopyala-Yapıştır": | |
| text_input = st.sidebar.text_area("Notları Yapıştırın", height=200) | |
| # Diğer parametreler | |
| lecture_name = st.sidebar.text_input("Ders Adı", value="Ders Adı") | |
| perfect_score = st.sidebar.number_input("Sınav Puanı Üst Limiti", value=100, step=1) | |
| my_note = st.sidebar.number_input("Benim Notum", value=0.0, step=0.1) | |
| note_s_axis_diff = st.sidebar.number_input("Notlar X Ekseni Ortak Farkı", value=5, step=1) | |
| amount_s_axis_diff = st.sidebar.number_input("Miktar Y Ekseni Ortak Farkı", value=1, step=1) | |
| first_step = st.sidebar.number_input("İlk Adım", value=0, step=1) | |
| increase_amount = st.sidebar.number_input("Artış Miktarı", value=1, step=1) | |
| if st.sidebar.button("Analizi Çalıştır"): | |
| if input_method == "Dosya Yükle" and uploaded_file is None: | |
| st.error(error_message) | |
| elif input_method == "Kopyala-Yapıştır" and not text_input: | |
| st.error(error_message) | |
| else: | |
| try: | |
| if uploaded_file: | |
| content = uploaded_file.read().decode("utf-8") | |
| elif text_input: | |
| content = text_input | |
| # Veriyi işleme | |
| result = re.split(r'[ \n]+', content) | |
| notes_result = result[first_step::increase_amount] | |
| notes_result = [x.strip() for x in notes_result if x.strip() != '∅' and x.strip() != "NA"] | |
| notes_result = list(map(lambda x: float(x), notes_result)) | |
| notes_result = np.array(notes_result) | |
| # İstatistikler | |
| average_x = np.average(notes_result) | |
| min_x = notes_result.min() | |
| max_x = notes_result.max() | |
| std = np.std(notes_result) | |
| z_score = (my_note - average_x) / std | |
| st.subheader(info_text_header) | |
| st.write(f"{participant_text}: {len(notes_result)}") | |
| st.write(f"{min_text}: {min_x:.2f}") | |
| st.write(f"{max_text}: {max_x:.2f}") | |
| st.write(f"{avg_text}: {average_x:.2f}") | |
| st.write(f"{std_dev_text}: {std:.2f}") | |
| st.write(f"{z_score_text}: {z_score:.2f}") | |
| # Grafik oluşturma | |
| unique_values, counts = np.unique(notes_result, return_counts=True) | |
| fig, ax = plt.subplots(figsize=(10, 6)) # Grafik boyutunu ayarlıyoruz | |
| bars = ax.bar(unique_values, counts, width=0.3) | |
| ax.axvline(x=average_x, color='red', linestyle='--') | |
| ax.text(average_x + 1.5, max(counts), f'{avg_text} ', color='red', rotation=0, ha='center', va='bottom') | |
| if my_note in unique_values: | |
| ax.text(my_note, counts[unique_values == my_note][0], f'{my_note}\n{z_score_text}', color='green', rotation=0, ha='center', va='bottom') | |
| for bar in bars: | |
| if bar.get_x() <= my_note < bar.get_x() + bar.get_width(): | |
| bar.set_color('green') | |
| ax.set_title(f'{lecture_name} {chart_title}') | |
| ax.set_xlabel(xlabel) | |
| ax.set_ylabel(ylabel) | |
| ax.set_xticks(range(0, int(perfect_score), note_s_axis_diff)) | |
| ax.set_yticks(range(0, max(counts), amount_s_axis_diff)) | |
| info_text = ( | |
| f"{participant_text}: {len(notes_result)}\n" | |
| f"{min_text}: {min_x:.2f}\n" | |
| f"{max_text}: {max_x:.2f}\n" | |
| f"{my_note} {avg_text}: {average_x:.2f}\n" | |
| f"{std_dev_text}: {std:.2f}\n" | |
| f"{z_score_text}: {z_score:.2f}" | |
| ) | |
| ax.text( | |
| 1.05 * max(unique_values), 0.8 * max(counts), | |
| info_text, | |
| fontsize=10, | |
| color="black", | |
| ha="left", | |
| va="top", | |
| bbox=dict(boxstyle="round,pad=0.3", edgecolor="blue", facecolor="lightgrey") | |
| ) | |
| # Grafik indirme bağlantısı | |
| buf = BytesIO() | |
| plt.savefig(buf, format="png") | |
| buf.seek(0) | |
| st.download_button( | |
| label=download_text, | |
| data=buf, | |
| file_name="not_dagilimi.png", | |
| mime="image/png" | |
| ) | |
| except Exception as e: | |
| st.error(f"Hata: {e}") | |