Update app.py
Browse files
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 "
|
| 7 |
|
| 8 |
try:
|
| 9 |
number = int(number)
|
| 10 |
-
table = f"
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return table
|
|
|
|
| 14 |
except ValueError:
|
| 15 |
-
return "
|
| 16 |
|
| 17 |
# Gradio interface
|
| 18 |
-
title = "Multiplication Table Chatbot"
|
| 19 |
description = """
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
"""
|
| 24 |
|
| 25 |
# Create Gradio interface
|
| 26 |
interface = gr.Interface(
|
| 27 |
-
fn=generate_table,
|
| 28 |
-
inputs=gr.Number(label="Enter a number (Type 0 to exit)"), #
|
| 29 |
-
outputs=gr.
|
| 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
|