Update app.py
Browse files
app.py
CHANGED
|
@@ -8,12 +8,12 @@ def generate_table(number):
|
|
| 8 |
try:
|
| 9 |
number = int(number)
|
| 10 |
table = f"<h2 style='color:green;'>π Multiplication Table for {number}:</h2><br>"
|
| 11 |
-
table += "<table style='border-collapse: collapse; width:
|
| 12 |
-
table += "<thead><tr style='background-color: #FFD700; color: #000;
|
| 13 |
|
| 14 |
for i in range(1, 11):
|
| 15 |
color = "#FFB6C1" if i % 2 == 0 else "#ADD8E6" # Alternate row colors
|
| 16 |
-
table += f"<tr style='background-color: {color};'><td>{number} x {i}</td><td>{number * i}</td></tr>"
|
| 17 |
|
| 18 |
table += "</table>"
|
| 19 |
return table
|
|
@@ -22,23 +22,69 @@ def generate_table(number):
|
|
| 22 |
return "<h3 style='color:red;'>β οΈ Please enter a valid number!</h3>"
|
| 23 |
|
| 24 |
# Gradio interface
|
| 25 |
-
title = "
|
| 26 |
description = """
|
| 27 |
-
Welcome to the fun and colorful multiplication chatbot for kids!
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
number = int(number)
|
| 10 |
table = f"<h2 style='color:green;'>π Multiplication Table for {number}:</h2><br>"
|
| 11 |
+
table += "<table style='border-collapse: collapse; width: 100%; text-align: center;'>"
|
| 12 |
+
table += "<thead><tr style='background-color: #FFD700; color: #000;'><th style='padding: 10px;'>Multiplier</th><th style='padding: 10px;'>Result</th></tr></thead>"
|
| 13 |
|
| 14 |
for i in range(1, 11):
|
| 15 |
color = "#FFB6C1" if i % 2 == 0 else "#ADD8E6" # Alternate row colors
|
| 16 |
+
table += f"<tr style='background-color: {color};'><td style='padding: 8px;'>{number} x {i}</td><td style='padding: 8px;'>{number * i}</td></tr>"
|
| 17 |
|
| 18 |
table += "</table>"
|
| 19 |
return table
|
|
|
|
| 22 |
return "<h3 style='color:red;'>β οΈ Please enter a valid number!</h3>"
|
| 23 |
|
| 24 |
# Gradio interface
|
| 25 |
+
title = "<span style='color:purple;'>π Multiplication Table Chatbot for Kids π</span>"
|
| 26 |
description = """
|
| 27 |
+
<h3 style='color:orange;'>π¨ Welcome to the fun and colorful multiplication chatbot for kids! π¨</h3>
|
| 28 |
+
<ul style="color:darkblue; font-size: 16px;">
|
| 29 |
+
<li>Type a number to see its vibrant multiplication table!</li>
|
| 30 |
+
<li>Type <b>0</b> to exit.</li>
|
| 31 |
+
</ul>
|
| 32 |
"""
|
| 33 |
|
| 34 |
+
# Define colorful input and output components
|
| 35 |
+
with gr.Blocks() as interface:
|
| 36 |
+
gr.Markdown(title)
|
| 37 |
+
gr.Markdown(description)
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
input_box = gr.Number(label="<span style='color:teal;'>Enter a number</span> π²", elem_id="input-box")
|
| 42 |
+
with gr.Column():
|
| 43 |
+
output_box = gr.HTML(label="<span style='color:crimson;'>Your Colorful Multiplication Table</span>", elem_id="output-box")
|
| 44 |
+
|
| 45 |
+
generate_button = gr.Button("π Generate Table π", elem_id="generate-button")
|
| 46 |
+
exit_message = gr.HTML(elem_id="exit-message")
|
| 47 |
+
|
| 48 |
+
# Link input and output
|
| 49 |
+
generate_button.click(
|
| 50 |
+
fn=generate_table,
|
| 51 |
+
inputs=input_box,
|
| 52 |
+
outputs=output_box,
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
# Add custom CSS for styling
|
| 56 |
+
interface.css = """
|
| 57 |
+
#input-box input {
|
| 58 |
+
background-color: #F0E68C;
|
| 59 |
+
color: #00008B;
|
| 60 |
+
font-size: 18px;
|
| 61 |
+
padding: 10px;
|
| 62 |
+
border: 2px solid #8A2BE2;
|
| 63 |
+
border-radius: 8px;
|
| 64 |
+
text-align: center;
|
| 65 |
+
}
|
| 66 |
+
#output-box {
|
| 67 |
+
background-color: #FFFACD;
|
| 68 |
+
color: #8B0000;
|
| 69 |
+
font-size: 16px;
|
| 70 |
+
padding: 15px;
|
| 71 |
+
border: 2px solid #FF4500;
|
| 72 |
+
border-radius: 10px;
|
| 73 |
+
overflow: auto;
|
| 74 |
+
}
|
| 75 |
+
#generate-button {
|
| 76 |
+
background-color: #7FFFD4;
|
| 77 |
+
color: #4B0082;
|
| 78 |
+
font-size: 18px;
|
| 79 |
+
padding: 10px 20px;
|
| 80 |
+
border-radius: 10px;
|
| 81 |
+
border: 2px solid #00CED1;
|
| 82 |
+
cursor: pointer;
|
| 83 |
+
transition: 0.3s ease;
|
| 84 |
+
}
|
| 85 |
+
#generate-button:hover {
|
| 86 |
+
background-color: #32CD32;
|
| 87 |
+
color: white;
|
| 88 |
+
}
|
| 89 |
+
"""
|
| 90 |
+
interface.launch()
|