Madiharehan commited on
Commit
933a2d1
Β·
verified Β·
1 Parent(s): 122adb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -19
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: 50%;'>"
12
- table += "<thead><tr style='background-color: #FFD700; color: #000; text-align: left;'><th>Multiplier</th><th>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>{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 = "🌈 Multiplication Table Chatbot for Kids 🌈"
26
  description = """
27
- Welcome to the fun and colorful multiplication chatbot for kids!
28
- 🎨 Enter a number to see a vibrant multiplication table.
29
- πŸšͺ Type 0 to say goodbye!
 
 
30
  """
31
 
32
- # Create Gradio interface
33
- interface = gr.Interface(
34
- fn=generate_table,
35
- inputs=gr.Number(label="Enter a number (Type 0 to exit)", precision=0), # Accept only integers
36
- outputs=gr.HTML(label="Your Colorful Multiplication Table"), # Display colorful HTML table
37
- title=title,
38
- description=description,
39
- allow_flagging="never", # Disable flagging
40
- )
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- # Launch the app
43
- if __name__ == "__main__":
44
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()