PruekRuek commited on
Commit
b8cf762
·
1 Parent(s): e15fc84
Files changed (2) hide show
  1. .streamlit/config.toml +0 -7
  2. src/streamlit_app.py +25 -15
.streamlit/config.toml DELETED
@@ -1,7 +0,0 @@
1
- [theme]
2
- base="dark"
3
- primaryColor="#1DB954"
4
- backgroundColor="#121212"
5
- secondaryBackgroundColor="#181818"
6
- textColor="#FFFFFF"
7
- font="monospace"
 
 
 
 
 
 
 
 
src/streamlit_app.py CHANGED
@@ -4,11 +4,16 @@ from io import StringIO
4
 
5
  st.set_page_config(page_title="Quiz Generation", layout="wide")
6
 
7
- # ---------- CSS: แต่งหน้าให้สวย ----------
8
  st.markdown("""
9
  <style>
10
- /* กำหนดความกว้างหน้ากระดาษ + จัดกลาง */
11
- .block-container {max-width: 980px; margin: 2rem auto;}
 
 
 
 
 
12
  /* การ์ดอัปโหลด */
13
  .upload-card{
14
  background: var(--secondary-background-color);
@@ -17,11 +22,13 @@ st.markdown("""
17
  padding: 28px 24px;
18
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
19
  }
 
20
  /* หัวการ์ด */
21
  .upload-title{
22
  display:flex; gap: 12px; align-items:center; margin-bottom: 8px;
23
  font-weight: 700; font-size: 22px;
24
  }
 
25
  /* ปรับสไตล์ dropzone ของ file_uploader */
26
  div[data-testid="stFileUploaderDropzone"]{
27
  border: 2px dashed rgba(0,0,0,.25);
@@ -33,7 +40,8 @@ div[data-testid="stFileUploaderDropzone"]:hover{
33
  border-color: #4f8bf9;
34
  background: rgba(79,139,249,0.06);
35
  }
36
- /* คำแนะนำใต้การ์ด */
 
37
  .hint{ color: #8a8a8a; font-size: 13px; margin-top: 4px; }
38
  .file-chip{
39
  display:inline-flex; align-items:center; gap:8px;
@@ -50,12 +58,12 @@ st.caption("อัปโหลดสไลด์/ไฟล์ข้อควา
50
  # ---------- Upload Card ----------
51
  st.markdown('<div class="upload-card">', unsafe_allow_html=True)
52
  st.markdown('<div class="upload-title">📘 Upload File</div>', unsafe_allow_html=True)
53
- st.write("") # ระยะห่างเล็กน้อย
54
 
55
  uploaded = st.file_uploader(
56
  "ลากไฟล์มาวาง หรือกดเพื่อเลือกไฟล์",
57
- type=["txt","pdf","docx","csv"],
58
- label_visibility="collapsed", # ซ่อน label เริ่มต้นให้สะอาดตา
59
  accept_multiple_files=False
60
  )
61
 
@@ -64,20 +72,22 @@ st.markdown("</div>", unsafe_allow_html=True) # ปิดการ์ด
64
 
65
  # ---------- Preview & Actions ----------
66
  if uploaded:
67
- # ชิปแสดงชื่อไฟล์
68
  st.markdown(f'<div class="file-chip">📄 {uploaded.name}</div>', unsafe_allow_html=True)
69
  st.divider()
70
 
71
- # ตัวอย่าง preview แบบง่าย
72
  if uploaded.type == "text/plain":
73
  text = uploaded.read().decode("utf-8", errors="ignore")
74
  st.subheader("Preview")
75
  st.text_area("เนื้อหาไฟล์", text, height=260, label_visibility="collapsed")
76
 
77
- # ตัวอย่าง export: ทำเป็น CSV mock
78
- df = pd.DataFrame([{"Question":"ใครเป็นผู้คิดค้นโทรศัพท์?","Answer":"Alexander Graham Bell"}])
79
- st.download_button("⬇️ ดาวน์โหลดตัวอย่าง Quiz (CSV)", df.to_csv(index=False).encode("utf-8"),
80
- file_name="quiz_sample.csv", mime="text/csv")
 
 
 
 
81
 
82
  elif uploaded.type == "text/csv":
83
  df = pd.read_csv(uploaded)
@@ -87,9 +97,9 @@ if uploaded:
87
  else:
88
  st.info("ไฟล์ PDF/DOCX จะอ่านได้หลังจากเพิ่มไลบรารีอ่านไฟล์ (เช่น pdfplumber / python-docx)")
89
 
90
- # ---------- (ตัวอย่าง) ปุ่มเริ่มสร้าง Quiz ----------
91
  with st.container():
92
  st.write("")
93
- col1, col2 = st.columns([1,2])
94
  if col1.button("🚀 สร้าง Quiz"):
95
  st.success("กำลังเตรียมประมวลผล… (ต่อเชื่อม NLP ได้ภายหลัง)")
 
4
 
5
  st.set_page_config(page_title="Quiz Generation", layout="wide")
6
 
7
+ # ---------- CSS ----------
8
  st.markdown("""
9
  <style>
10
+ /* ซ่อนกล่อง text input ของ Streamlit (กันแถบขาวลอย ๆ) */
11
+ [data-testid="stTextInput"],
12
+ [data-testid="stDecoratedTextInput"] { display: none !important; }
13
+
14
+ /* กำหนดความกว้างหน้า + จัดกลาง */
15
+ .block-container { max-width: 980px; margin: 2rem auto; }
16
+
17
  /* การ์ดอัปโหลด */
18
  .upload-card{
19
  background: var(--secondary-background-color);
 
22
  padding: 28px 24px;
23
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
24
  }
25
+
26
  /* หัวการ์ด */
27
  .upload-title{
28
  display:flex; gap: 12px; align-items:center; margin-bottom: 8px;
29
  font-weight: 700; font-size: 22px;
30
  }
31
+
32
  /* ปรับสไตล์ dropzone ของ file_uploader */
33
  div[data-testid="stFileUploaderDropzone"]{
34
  border: 2px dashed rgba(0,0,0,.25);
 
40
  border-color: #4f8bf9;
41
  background: rgba(79,139,249,0.06);
42
  }
43
+
44
+ /* คำแนะนำ/ชิปชื่อไฟล์ */
45
  .hint{ color: #8a8a8a; font-size: 13px; margin-top: 4px; }
46
  .file-chip{
47
  display:inline-flex; align-items:center; gap:8px;
 
58
  # ---------- Upload Card ----------
59
  st.markdown('<div class="upload-card">', unsafe_allow_html=True)
60
  st.markdown('<div class="upload-title">📘 Upload File</div>', unsafe_allow_html=True)
61
+ st.write("")
62
 
63
  uploaded = st.file_uploader(
64
  "ลากไฟล์มาวาง หรือกดเพื่อเลือกไฟล์",
65
+ type=["txt", "pdf", "docx", "csv"],
66
+ label_visibility="collapsed",
67
  accept_multiple_files=False
68
  )
69
 
 
72
 
73
  # ---------- Preview & Actions ----------
74
  if uploaded:
 
75
  st.markdown(f'<div class="file-chip">📄 {uploaded.name}</div>', unsafe_allow_html=True)
76
  st.divider()
77
 
 
78
  if uploaded.type == "text/plain":
79
  text = uploaded.read().decode("utf-8", errors="ignore")
80
  st.subheader("Preview")
81
  st.text_area("เนื้อหาไฟล์", text, height=260, label_visibility="collapsed")
82
 
83
+ # ตัวอย่าง export CSV mock
84
+ df = pd.DataFrame([{"Question": "ใครเป็นผู้คิดค้นโทรศัพท์?", "Answer": "Alexander Graham Bell"}])
85
+ st.download_button(
86
+ "⬇️ ดาวน์โหลดตัวอย่าง Quiz (CSV)",
87
+ df.to_csv(index=False).encode("utf-8"),
88
+ file_name="quiz_sample.csv",
89
+ mime="text/csv"
90
+ )
91
 
92
  elif uploaded.type == "text/csv":
93
  df = pd.read_csv(uploaded)
 
97
  else:
98
  st.info("ไฟล์ PDF/DOCX จะอ่านได้หลังจากเพิ่มไลบรารีอ่านไฟล์ (เช่น pdfplumber / python-docx)")
99
 
100
+ # ---------- Action ----------
101
  with st.container():
102
  st.write("")
103
+ col1, col2 = st.columns([1, 2])
104
  if col1.button("🚀 สร้าง Quiz"):
105
  st.success("กำลังเตรียมประมวลผล… (ต่อเชื่อม NLP ได้ภายหลัง)")