Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ IMAGE_FOLDER = "IMAGES/"
|
|
10 |
# Dictionary of words associated with each letter
|
11 |
letter_words = {
|
12 |
"A": "Apple", "B": "Bat", "C": "Cat", "D": "Duck", "E": "Eyes", "F": "Fish"
|
13 |
-
|
14 |
|
15 |
# Load all alphabet images into a dictionary {Letter: Image Path}
|
16 |
alphabet_data = {f.split(".")[0].upper(): os.path.join(IMAGE_FOLDER, f)
|
@@ -32,16 +32,57 @@ def get_random_image():
|
|
32 |
|
33 |
return image_path, sentence, temp_audio.name # Returns image, sentence, and audio file path
|
34 |
|
35 |
-
# Gradio UI
|
36 |
-
with gr.Blocks(
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
audio_output = gr.Audio()
|
43 |
|
44 |
-
next_btn = gr.Button("Next Letter")
|
45 |
|
46 |
next_btn.click(get_random_image, inputs=[], outputs=[img_display, text_display, audio_output])
|
47 |
|
|
|
10 |
# Dictionary of words associated with each letter
|
11 |
letter_words = {
|
12 |
"A": "Apple", "B": "Bat", "C": "Cat", "D": "Duck", "E": "Eyes", "F": "Fish"
|
13 |
+
}
|
14 |
|
15 |
# Load all alphabet images into a dictionary {Letter: Image Path}
|
16 |
alphabet_data = {f.split(".")[0].upper(): os.path.join(IMAGE_FOLDER, f)
|
|
|
32 |
|
33 |
return image_path, sentence, temp_audio.name # Returns image, sentence, and audio file path
|
34 |
|
35 |
+
# Gradio UI with Animations & Styling
|
36 |
+
with gr.Blocks(css="""
|
37 |
+
body {
|
38 |
+
background-color: #f8f9fa;
|
39 |
+
}
|
40 |
+
.title {
|
41 |
+
text-align: center;
|
42 |
+
font-size: 2.5rem;
|
43 |
+
font-weight: bold;
|
44 |
+
color: #333;
|
45 |
+
padding-bottom: 10px;
|
46 |
+
}
|
47 |
+
.sub-title {
|
48 |
+
text-align: center;
|
49 |
+
font-size: 1.2rem;
|
50 |
+
color: #666;
|
51 |
+
margin-bottom: 20px;
|
52 |
+
}
|
53 |
+
.container {
|
54 |
+
max-width: 500px;
|
55 |
+
margin: auto;
|
56 |
+
text-align: center;
|
57 |
+
}
|
58 |
+
.gradio-image img {
|
59 |
+
border-radius: 20px;
|
60 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
|
61 |
+
}
|
62 |
+
.gradio-button {
|
63 |
+
font-size: 1.2rem;
|
64 |
+
padding: 10px;
|
65 |
+
border-radius: 15px;
|
66 |
+
background: linear-gradient(135deg, #ff7eb3, #ff758c);
|
67 |
+
color: white;
|
68 |
+
border: none;
|
69 |
+
cursor: pointer;
|
70 |
+
transition: transform 0.2s ease;
|
71 |
+
}
|
72 |
+
.gradio-button:hover {
|
73 |
+
transform: scale(1.05);
|
74 |
+
}
|
75 |
+
""") as demo:
|
76 |
+
gr.Markdown("<div class='title'>🔤 Alphabet Learning Game with Audio</div>")
|
77 |
+
|
78 |
|
79 |
+
with gr.Row():
|
80 |
+
img_display = gr.Image(label="Letter Image", elem_classes="gradio-image")
|
81 |
+
|
82 |
+
text_display = gr.Textbox(label="What you hear", interactive=False)
|
83 |
audio_output = gr.Audio()
|
84 |
|
85 |
+
next_btn = gr.Button("🎵 Next Letter", elem_classes="gradio-button")
|
86 |
|
87 |
next_btn.click(get_random_image, inputs=[], outputs=[img_display, text_display, audio_output])
|
88 |
|