Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the app
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
interface.launch()
|