Shivraj8615 commited on
Commit
2bce61c
Β·
verified Β·
1 Parent(s): d8f0ff3

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +105 -0
  2. requirements.txt +2 -0
  3. script.py +24 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ import os
4
+ import random
5
+ from PIL import Image
6
+ from pathlib import Path
7
+ import base64
8
+
9
+ # Page configuration
10
+ st.set_page_config(page_title="πŸͺ– PPDT Test Simulator", layout="centered", initial_sidebar_state="collapsed")
11
+
12
+ # Custom CSS styling
13
+ st.markdown("""
14
+ <style>
15
+ .centered {
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ height: 80vh;
20
+ font-size: 2rem;
21
+ color: white;
22
+ background-color: black;
23
+ border-radius: 10px;
24
+ }
25
+ .button-style {
26
+ width: 100%;
27
+ font-size: 18px;
28
+ padding: 10px;
29
+ border-radius: 8px;
30
+ }
31
+ </style>
32
+ """, unsafe_allow_html=True)
33
+
34
+ # Helper function to show full screen image
35
+ def show_fullscreen_image(img_path, duration, caption=""):
36
+ image = Image.open(img_path)
37
+ st.image(image, use_column_width=True, caption=caption)
38
+ time.sleep(duration)
39
+ st.empty()
40
+
41
+ # Play audio using base64 encoding
42
+ def play_audio(file_path):
43
+ with open(file_path, "rb") as f:
44
+ audio_bytes = f.read()
45
+ audio_b64 = base64.b64encode(audio_bytes).decode()
46
+ audio_html = f"""
47
+ <audio autoplay>
48
+ <source src="data:audio/mp3;base64,{audio_b64}" type="audio/mp3">
49
+ </audio>
50
+ """
51
+ st.markdown(audio_html, unsafe_allow_html=True)
52
+
53
+ # Show black screen with a message
54
+ def show_black_screen(message, duration):
55
+ st.markdown(f"<div class='centered'>{message}</div>", unsafe_allow_html=True)
56
+ time.sleep(duration)
57
+ st.empty()
58
+
59
+ # Title
60
+ st.markdown("<h1 style='text-align: center;'>πŸͺ– PPDT Test Simulator</h1>", unsafe_allow_html=True)
61
+ st.markdown("<h4 style='text-align: center;'>Simulate Real-Time Picture Perception and Discussion Test</h4>", unsafe_allow_html=True)
62
+ st.write("")
63
+
64
+ # Main Buttons
65
+ col1, col2 = st.columns(2)
66
+ with col1:
67
+ show_instruction = st.button("πŸ“˜ Show Instructions", type="primary")
68
+ with col2:
69
+ start_test = st.button("🚩 Start New PPDT", type="primary")
70
+
71
+ # === Instructions Flow ===
72
+ if show_instruction:
73
+ st.info("πŸ” Showing Instruction Page 1...")
74
+ show_fullscreen_image("images/instr1.jpg", 30, "Instruction Page 1 (30 seconds)")
75
+
76
+ st.info("πŸ” Showing Instruction Page 2...")
77
+ show_fullscreen_image("images/instr2.jpg", 30, "Instruction Page 2 (30 seconds)")
78
+
79
+ st.success("βœ… Instructions Complete! You're ready for the test.")
80
+
81
+ # === Test Flow ===
82
+ if start_test:
83
+ st.warning("πŸ•’ Get Ready... Test will begin shortly.")
84
+ time.sleep(5)
85
+
86
+ # Load random image from test image folder
87
+ image_folder = "images"
88
+ test_images = [f for f in os.listdir(image_folder) if f.lower().endswith((".jpg", ".png")) and "test" in f.lower()]
89
+ selected_image = random.choice(test_images)
90
+
91
+ # Show PPDT image
92
+ st.info("πŸ“Έ Observe the image carefully...")
93
+ show_fullscreen_image(os.path.join(image_folder, selected_image), 20, "Observe for 20 seconds")
94
+
95
+ # Black screen for 30 seconds
96
+ show_black_screen("🧠 Think and prepare your story...", 30)
97
+ play_audio("sounds/bell1.mp3")
98
+
99
+ # Writing time: 4 minutes
100
+ show_black_screen("πŸ“ Write your story now (4 minutes)...", 240)
101
+ play_audio("sounds/bell2.mp3")
102
+
103
+ st.balloons()
104
+ st.success("🎯 Test Finished! Well done, candidate!")
105
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit>=1.32.0
2
+ Pillow>=10.0.0
script.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # === Settings ===
4
+ folder_path = "pics" # Change this if your folder is named differently
5
+ file_extensions = (".jpg", ".jpeg", ".png")
6
+
7
+ # === Rename Logic ===
8
+ def rename_images_in_folder(path):
9
+ files = [f for f in os.listdir(path) if f.lower().endswith(file_extensions)]
10
+ files.sort() # Optional: Ensures consistent order
11
+
12
+ for idx, filename in enumerate(files, start=1):
13
+ extension = os.path.splitext(filename)[1]
14
+ new_name = f"test{idx}{extension.lower()}"
15
+ src = os.path.join(path, filename)
16
+ dst = os.path.join(path, new_name)
17
+ os.rename(src, dst)
18
+ print(f"Renamed: {filename} β†’ {new_name}")
19
+
20
+ print("\nβœ… Renaming complete!")
21
+
22
+ # === Run Script ===
23
+ if __name__ == "__main__":
24
+ rename_images_in_folder(folder_path)