Huy0502 commited on
Commit
0a47da9
·
verified ·
1 Parent(s): f85162a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -65
app.py CHANGED
@@ -1,73 +1,55 @@
 
1
  import streamlit as st
2
- from random import random
3
- import pandas as pd
4
- from transformers import pipeline
5
 
6
- #-----------------------FUNCTIONS-----------------------
7
- # Đọc và xử lý dữ liệu
8
- @st.cache_data
9
- def load_data(file_path):
10
- df = pd.read_csv(file_path)
11
- return df
12
 
13
- # Đề xuất chủ đề sử dụng Zero-shot classification
14
- def suggest_topics(text, classifier, topics):
15
- prediction = classifier(text, topics)
16
- return prediction["labels"][0]
17
-
18
- # Thiết lập pipeline cho zero-shot classification
19
- classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
20
-
21
- # Các chủ đề có thể
22
- possible_topics = ["Kinh tế", "Du lịch", "Giao tiếp", "Công nghệ", "Giáo dục"]
23
-
24
- # Load data
25
- data_path = "Toeic.csv"
26
- df = load_data(data_path)
27
-
28
-
29
- #----------------------------------Frontend--------------------------------
30
- # Giao diện người dùng
31
  st.markdown("<h1 style='text-align: center;'>Chương trình ôn tập từ vựng Toeic</h1>", unsafe_allow_html=True)
32
  st.markdown("<h3 style='text-align: center;'>Dành cho bé iu của anh❤️</h3>", unsafe_allow_html=True)
33
 
34
- # Thêm thanh bên để chọn chế độ ôn tập
35
- mode = st.sidebar.selectbox(
36
- "Chọn chế độ ôn tập:",
37
- ["Flashcard", "Trắc nghiệm", "Thử thách tốc độ", "Ôn tập theo chủ đề", "Kiểm tra"]
38
  )
39
 
40
- # Hiển thị flashcards
41
- if mode == "Flashcard":
42
- st.subheader("Flashcard Từ vựng")
43
- word = st.selectbox("Chọn từ:", df["Từ vựng"])
44
- if st.button("Hiện nghĩa"):
45
- definition = df[df["Từ vựng"] == word]["Nghĩa"].values[0]
46
- st.write("Nghĩa của từ:", definition)
47
-
48
- # Trắc nghiệm
49
- elif mode == "Trắc nghiệm":
50
- st.subheader("Trắc nghiệm")
51
- questions = df.sample(5)
52
- correct_answers = 0
53
- for i, row in questions.iterrows():
54
- options = df["Nghĩa"].sample(3).tolist() + [row["Nghĩa"]]
55
- shuffled_options = random.sample(options, len(options))
56
- user_answer = st.radio(f"{row['Từ vựng']} có nghĩa là gì?", options=shuffled_options, key=i)
57
- if st.button("Kiểm tra", key=i):
58
- if user_answer == row["Nghĩa"]:
59
- st.success("Đúng!")
60
- correct_answers += 1
61
- else:
62
- st.error("Sai!")
63
- st.write(f"Điểm của bạn: {correct_answers}/5")
64
-
65
- # Cập nhật chủ đề nếu cần
66
- if st.button("Cập nhật Chủ đề cho Từ Vựng"):
67
- for i, row in df.iterrows():
68
- if pd.isna(row["Chủ đề"]):
69
- df.at[i, "Chủ đề"] = suggest_topics(row["Từ vựng"], classifier, possible_topics)
70
- df.to_csv(data_path, index=False)
71
- st.success("Đã cập nhật chủ đề cho từ vựng!")
72
-
73
- st.markdown("<h3 style='text-align: center;'>Chúc bé iu của anh thi đậu nhé😘</h3>", unsafe_allow_html=True)
 
 
 
 
 
1
+ import time
2
  import streamlit as st
3
+ from Toeic_manager import ToeicVocabularyApp
 
 
4
 
5
+ # Khởi tạo đối tượng app từ class ToeicVocabularyApp
6
+ app = ToeicVocabularyApp('toeic_vocabulary.csv')
 
 
 
 
7
 
8
+ # Thiết lập tiêu đề chính phụ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  st.markdown("<h1 style='text-align: center;'>Chương trình ôn tập từ vựng Toeic</h1>", unsafe_allow_html=True)
10
  st.markdown("<h3 style='text-align: center;'>Dành cho bé iu của anh❤️</h3>", unsafe_allow_html=True)
11
 
12
+ # Sidebar để chọn cài đặt ứng dụng hoặc chế độ ôn tập
13
+ sidebar_choice = st.sidebar.selectbox(
14
+ "Menu",
15
+ ["Cài đặt ứng dụng", "Chế độ ôn tập"]
16
  )
17
 
18
+ # Cài đặt ứng dụng
19
+ if sidebar_choice == "Cài đặt ứng dụng":
20
+ st.subheader("Cài đặt Ứng Dụng")
21
+ # Cho phép người dùng điều chỉnh các cài đặt
22
+ time_limit = st.slider("Thiết lập thời gian cho Thử thách tốc độ (giây)", min_value=10, max_value=120, value=30)
23
+ app.update_settings("time_limit", time_limit)
24
+ if st.button("Lưu Cài Đặt"):
25
+ st.success("Cài đặt đã được lưu thành công!")
26
+
27
+ # Chế độ ôn tập
28
+ elif sidebar_choice == "Chế độ ôn tập":
29
+ st.subheader("Chọn Chế độ Ôn tập")
30
+ study_mode = st.selectbox(
31
+ "Chọn chế độ",
32
+ app.settings["study_mode"]
33
+ )
34
+
35
+ if study_mode == "Thử thách tốc độ":
36
+ # Đếm ngược thời gian cho Thử thách tốc độ
37
+ st.subheader("Thử thách tốc độ")
38
+ st.write("Thời gian: ", app.settings["time_limit"], " giây")
39
+ # Đặt một nút để bắt đầu thử thách
40
+ if st.button("Bắt đầu"):
41
+ st.write("Thử thách bắt đầu!")
42
+ # Thêm mã cho tính năng đếm ngược ở đây
43
+ # Đây một giả lập, bạn sẽ cần sử dụng thư viện khác để xử lý đếm ngược thực tế
44
+ countdown = app.settings["time_limit"]
45
+ for i in range(countdown, 0, -1):
46
+ st.write(i)
47
+ time.sleep(1)
48
+ st.write("Hết giờ!")
49
+
50
+ # Đối với các chế độ ôn tập khác, hiển thị thông tin tương ứng
51
+ else:
52
+ st.write(f"Chế độ {study_mode} được chọn")
53
+
54
+ # Tiêu đề chân trang
55
+ st.markdown("<h3 style='text-align: center;'>Chúc bé iu của anh thi đậu nhé😘</h3>", unsafe_allow_html=True)