Madiharehan commited on
Commit
122adb1
Β·
verified Β·
1 Parent(s): 82c0d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,32 +1,39 @@
1
  import gradio as gr
2
 
3
- # Function to generate multiplication table
4
  def generate_table(number):
5
  if number == 0:
6
- return "πŸ‘‹ Thank you for using the chatbot! Goodbye!"
7
 
8
  try:
9
  number = int(number)
10
- table = f"πŸ“‹ Multiplication Table for {number}:\n\n"
11
- for i in range(1, 11): # Generate table from 1 to 10
12
- table += f"{number} x {i} = {number * i}\n"
 
 
 
 
 
 
13
  return table
 
14
  except ValueError:
15
- return "⚠️ Please enter a valid number!"
16
 
17
  # Gradio interface
18
- title = "Multiplication Table Chatbot"
19
  description = """
20
- This chatbot generates the multiplication table of any number you provide!
21
- - Type a number to see its table.
22
- - Type 0 to end the interaction.
23
  """
24
 
25
  # Create Gradio interface
26
  interface = gr.Interface(
27
- fn=generate_table, # Function to call
28
- inputs=gr.Number(label="Enter a number (Type 0 to exit)"), # Input field
29
- outputs=gr.Textbox(label="Result"), # Output field
30
  title=title,
31
  description=description,
32
  allow_flagging="never", # Disable flagging
 
1
  import gradio as gr
2
 
3
+ # Function to generate a colorful multiplication table
4
  def generate_table(number):
5
  if number == 0:
6
+ return "<h2 style='color:blue;'>πŸ‘‹ Thank you for using the chatbot! Goodbye!</h2>"
7
 
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
20
+
21
  except ValueError:
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