Spaces:
Runtime error
Runtime error
File size: 8,520 Bytes
6cd4037 58b4723 6cd4037 58b4723 6cd4037 58b4723 6cd4037 b4b8bc8 6cd4037 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
import csv
import streamlit as st
import numpy as np
import cv2
from PIL import Image
from functions import image_show
import pandas as pd
from data_func import make_new_data,update,save_and_push
import os
from huggingface_hub import Repository
import reader
st.markdown("""
<style>
.block-container {
padding-top: 1rem;
padding-bottom: 0rem;
padding-left: 1rem;
padding-right: 1rem;
}
</style>
""", unsafe_allow_html=True)
def pull_read(DATASET_REPO_URL,HF_TOKEN,DATA_FILE):
repo = Repository(
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
)
with open(DATA_FILE) as csvfile:
df = pd.read_csv(csvfile)
df = pd.DataFrame(df)
return repo, df
@st.cache
def convert_df_to_csv(df):
# IMPORTANT: Cache the conversion to prevent computation on every rerun
return df.to_csv().encode('utf-8')
def screen_scan_main():
teacher_code = st.text_input("Ogretmen kodu:",key=12)
password = st.text_input("Sıfre:",key=17,type="password")
teacher_code = str(teacher_code)
password = str(password)
DATA_FILENAME = f"{teacher_code}.csv"
DATA_FILENAME = str(DATA_FILENAME)
image_file = st.file_uploader(
"Tarama Yapmak Icin Optigi Yukleyin", type=['jpeg', 'png', 'jpg', 'webp'])
if image_file != None:
repo, repo_df = pull_read(DATASET_REPO_URL = "https://huggingface.co/datasets/mertbozkurt/school_data",
DATA_FILE = os.path.join("data", DATA_FILENAME),
HF_TOKEN = "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")
repo.git_pull()
if str(repo_df["ogrenci_no"][0]) == password:
st.write("Giriş başarılı")
answer_code = st.radio(
"Cevap Anahtari Kodu",
('1', '2', '3',"4","5"))
answer_code = int(answer_code)
global myIndexs
image = Image.open(image_file)
image = np.array(image.convert('RGB'))
#(ans_txt,pathImage, save_images= True)
resim_list,myIndexs =reader.reader(pathImage=image,save_images=False)
#myIndex1_str =", ".join(map(str, myIndexs[0]))
st.write("Cevap Anahtari")
df = pd.DataFrame(
[
{"Sorular": "Ders 1 Soru1 ", "Cevap": myIndexs[0][0]},
{"Sorular": "Ders 1 Soru2", "Cevap": myIndexs[0][1]},
{"Sorular": "Ders 1 Soru3", "Cevap": myIndexs[0][2]},
{"Sorular": "Ders 1 Soru4 ", "Cevap": myIndexs[0][3]},
{"Sorular": "Ders 1 Soru5", "Cevap": myIndexs[0][4]},
{"Sorular": "Ders 1 Soru6 ", "Cevap": myIndexs[0][5]},
{"Sorular": "Ders 1 Soru7", "Cevap": myIndexs[0][6]},
{"Sorular": "Ders 1 Soru8", "Cevap": myIndexs[0][7]},
{"Sorular": "Ders 1 Soru9 ", "Cevap": myIndexs[0][8]},
{"Sorular": "Ders 1 Soru10", "Cevap": myIndexs[0][9]},
{"Sorular": "Ders 1 Soru11 ", "Cevap": myIndexs[0][10]},
{"Sorular": "Ders 1 Soru12", "Cevap": myIndexs[0][11]},
{"Sorular": "Ders 1 Soru13", "Cevap": myIndexs[0][12]},
{"Sorular": "Ders 1 Soru14 ", "Cevap": myIndexs[0][13]},
{"Sorular": "Ders 1 Soru15", "Cevap": myIndexs[0][14]},
{"Sorular": "Ders 1 Soru16 ", "Cevap": myIndexs[0][15]},
{"Sorular": "Ders 1 Soru17", "Cevap": myIndexs[0][16]},
{"Sorular": "Ders 1 Soru18", "Cevap": myIndexs[0][17]},
{"Sorular": "Ders 1 Soru19 ", "Cevap": myIndexs[0][18]},
{"Sorular": "Ders 1 Soru20", "Cevap": myIndexs[0][19]},
{"Sorular": "Ders 2 Soru1 ", "Cevap": myIndexs[1][0]},
{"Sorular": "Ders 2 Soru2", "Cevap": myIndexs[1][1]},
{"Sorular": "Ders 2 Soru3", "Cevap": myIndexs[1][2]},
{"Sorular": "Ders 2 Soru4 ", "Cevap": myIndexs[1][3]},
{"Sorular": "Ders 2 Soru5", "Cevap": myIndexs[1][4]},
{"Sorular": "Ders 2 Soru6 ", "Cevap": myIndexs[1][5]},
{"Sorular": "Ders 2 Soru7", "Cevap": myIndexs[1][6]},
{"Sorular": "Ders 2 Soru8", "Cevap": myIndexs[1][7]},
{"Sorular": "Ders 2 Soru9 ", "Cevap": myIndexs[1][8]},
{"Sorular": "Ders 2 Soru10", "Cevap": myIndexs[1][9]},
{"Sorular": "Ders 2 Soru11 ", "Cevap": myIndexs[1][10]},
{"Sorular": "Ders 2 Soru12", "Cevap": myIndexs[1][11]},
{"Sorular": "Ders 2 Soru13", "Cevap": myIndexs[1][12]},
{"Sorular": "Ders 2 Soru14 ", "Cevap": myIndexs[1][13]},
{"Sorular": "Ders 2 Soru15", "Cevap": myIndexs[1][14]},
{"Sorular": "Ders 2 Soru16 ", "Cevap": myIndexs[1][15]},
{"Sorular": "Ders 2 Soru17", "Cevap": myIndexs[1][16]},
{"Sorular": "Ders 2 Soru18", "Cevap": myIndexs[1][17]},
{"Sorular": "Ders 2 Soru19 ", "Cevap": myIndexs[1][18]},
{"Sorular": "Ders 2 Soru20", "Cevap": myIndexs[1][19]},
{"Sorular": "Ders 3 Soru1 ", "Cevap": myIndexs[2][0]},
{"Sorular": "Ders 3 Soru2", "Cevap": myIndexs[2][1]},
{"Sorular": "Ders 3 Soru3", "Cevap": myIndexs[2][2]},
{"Sorular": "Ders 3 Soru4 ", "Cevap": myIndexs[2][3]},
{"Sorular": "Ders 3 Soru5", "Cevap": myIndexs[2][4]},
{"Sorular": "Ders 3 Soru6 ", "Cevap": myIndexs[2][5]},
{"Sorular": "Ders 3 Soru7", "Cevap": myIndexs[2][6]},
{"Sorular": "Ders 3 Soru8", "Cevap": myIndexs[2][7]},
{"Sorular": "Ders 3 Soru9 ", "Cevap": myIndexs[2][8]},
{"Sorular": "Ders 3 Soru10", "Cevap": myIndexs[2][9]},
{"Sorular": "Ders 3 Soru11 ", "Cevap": myIndexs[2][10]},
{"Sorular": "Ders 3 Soru12", "Cevap": myIndexs[2][11]},
{"Sorular": "Ders 3 Soru13", "Cevap": myIndexs[2][12]},
{"Sorular": "Ders 3 Soru14 ", "Cevap": myIndexs[2][13]},
{"Sorular": "Ders 3 Soru15", "Cevap": myIndexs[2][14]},
{"Sorular": "Ders 3 Soru16 ", "Cevap": myIndexs[2][15]},
{"Sorular": "Ders 3 Soru17", "Cevap": myIndexs[2][16]},
{"Sorular": "Ders 3 Soru18", "Cevap": myIndexs[2][17]},
{"Sorular": "Ders 3 Soru19 ", "Cevap": myIndexs[2][18]},
{"Sorular": "Ders 3 Soru20", "Cevap": myIndexs[2][19]}
]
)
edited_df = st.experimental_data_editor(df,use_container_width=True,height=400)
if st.button("Kaydet"):
repo, repo_df = pull_read(DATASET_REPO_URL = "https://huggingface.co/datasets/mertbozkurt/school_data",
DATA_FILE = os.path.join("data", DATA_FILENAME),
HF_TOKEN = "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")
repo.git_pull()
image = Image.open(image_file)
image = np.array(image.convert('RGB'))
#(ans_txt,pathImage, save_images= True)
myIndex1_str =",".join(map(str, edited_df["Cevap"]))
myIndex2_str =",".join(map(str, myIndexs[1]))
myIndex3_str =",".join(map(str, myIndexs[2]))
#new_data1 = pd.DataFrame(data, index, columns)
data = [[1,answer_code,80,myIndex1_str,90,myIndex2_str,10,myIndex3_str]]
# Create the pandas DataFrame
new_data = pd.DataFrame(data, columns=['sinav_kodu', 'ogrenci_no',
"notu1","yanlis_sorulari1",
"notu2","yanlis_sorulari2",
"notu3","yanlis_sorulari3"])
repo_df = repo_df[repo_df['ogrenci_no'] != answer_code]
updated = update(new_data=new_data,ex_df=repo_df)
#st.dataframe(updated,use_container_width=True)
save_and_push(dataFrame=updated,repo=repo,fileName=f"data/{DATA_FILENAME}")
#st.download_button(label="Tum verileri indirmek icin tiklayin",data=convert_df_to_csv(updated),
# file_name=f'{teacher_code}.csv',mime='text/csv',)
else:
st.write("Giris basarisiz kontrol ediniz.")
#python -m streamlit run app.py
if __name__ == '__main__':
screen_scan_main() |