Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
color_schemes = [
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Function to generate a colorful multiplication table for a given number
|
| 8 |
def generate_table(number):
|
|
@@ -10,20 +17,27 @@ def generate_table(number):
|
|
| 10 |
try:
|
| 11 |
number = int(number)
|
| 12 |
|
| 13 |
-
# Select the color based on the color_index
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
table
|
| 18 |
-
table += "<
|
|
|
|
| 19 |
|
| 20 |
for i in range(1, 11):
|
| 21 |
-
|
|
|
|
| 22 |
table += f"<tr style='background-color: {row_color};'><td style='padding: 8px;'>{number} x {i}</td><td style='padding: 8px;'>{number * i}</td></tr>"
|
| 23 |
|
| 24 |
table += "</table>"
|
| 25 |
|
| 26 |
-
# Update color index to the next color (cycle back to 0 after 5)
|
| 27 |
color_index = (color_index + 1) % len(color_schemes)
|
| 28 |
|
| 29 |
return table
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# List of color schemes for the entire table (5 color schemes)
|
| 4 |
+
color_schemes = [
|
| 5 |
+
{"header": "#FFD700", "row_even": "#ADD8E6", "row_odd": "#FFB6C1", "border": "#FF6347"}, # Gold, Light Blue, Pink
|
| 6 |
+
{"header": "#FF4500", "row_even": "#FFE4B5", "row_odd": "#FF6347", "border": "#8B0000"}, # Orange Red, Light Gold, Red
|
| 7 |
+
{"header": "#98FB98", "row_even": "#E0FFFF", "row_odd": "#FFFAF0", "border": "#32CD32"}, # Light Green, Light Cyan, Ivory
|
| 8 |
+
{"header": "#8A2BE2", "row_even": "#F0E68C", "row_odd": "#DA70D6", "border": "#800080"}, # Blue Violet, Khaki, Orchid
|
| 9 |
+
{"header": "#20B2AA", "row_even": "#F0FFF0", "row_odd": "#F5FFFA", "border": "#006400"} # Light Sea Green, Honeydew
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
color_index = 0 # This will track the current color scheme in the list
|
| 13 |
|
| 14 |
# Function to generate a colorful multiplication table for a given number
|
| 15 |
def generate_table(number):
|
|
|
|
| 17 |
try:
|
| 18 |
number = int(number)
|
| 19 |
|
| 20 |
+
# Select the color scheme based on the color_index
|
| 21 |
+
color_scheme = color_schemes[color_index]
|
| 22 |
+
|
| 23 |
+
header_color = color_scheme["header"]
|
| 24 |
+
even_row_color = color_scheme["row_even"]
|
| 25 |
+
odd_row_color = color_scheme["row_odd"]
|
| 26 |
+
border_color = color_scheme["border"]
|
| 27 |
|
| 28 |
+
# Construct the multiplication table
|
| 29 |
+
table = f"<h2 style='color:{header_color};'>📋 Multiplication Table for {number}:</h2><br>"
|
| 30 |
+
table += f"<table style='border-collapse: collapse; width: 100%; text-align: center; border: 2px solid {border_color};'>"
|
| 31 |
+
table += "<thead><tr style='background-color: {header_color}; color: #000;'><th style='padding: 10px;'>Multiplier</th><th style='padding: 10px;'>Result</th></tr></thead>"
|
| 32 |
|
| 33 |
for i in range(1, 11):
|
| 34 |
+
# Alternate row colors based on even/odd rows
|
| 35 |
+
row_color = even_row_color if i % 2 == 0 else odd_row_color
|
| 36 |
table += f"<tr style='background-color: {row_color};'><td style='padding: 8px;'>{number} x {i}</td><td style='padding: 8px;'>{number * i}</td></tr>"
|
| 37 |
|
| 38 |
table += "</table>"
|
| 39 |
|
| 40 |
+
# Update color index to the next color scheme (cycle back to 0 after 5)
|
| 41 |
color_index = (color_index + 1) % len(color_schemes)
|
| 42 |
|
| 43 |
return table
|