codeboosterstech commited on
Commit
4df2b39
·
verified ·
1 Parent(s): f397005

Add app.py via Space Creator

Browse files
Files changed (1) hide show
  1. app.py +26 -77
app.py CHANGED
@@ -1,82 +1,31 @@
1
  import gradio as gr
2
 
3
- # Original code snippet
4
- # def add(a, b):
5
- # return a + b
6
- #
7
- # def subtract(a, b):
8
- # return a - b
9
- #
10
- # def multiply(a, b):
11
- # return a * b
12
- #
13
- # def divide(a, b):
14
- # if b == 0:
15
- # return "Error: Cannot divide by zero"
16
- # return a / b
17
- #
18
- # def calculator():
19
- # print("Simple Calculator")
20
- # print("Operations: + - * /")
21
- #
22
- # while True:
23
- # op = input("Enter operation (+, -, *, /) or 'q' to quit: ")
24
- #
25
- # if op.lower() == 'q':
26
- # print("Exiting calculator.")
27
- # break
28
- #
29
- # if op not in ['+', '-', '*', '/']:
30
- # print("Invalid operation.")
31
- # continue
32
- #
33
- # try:
34
- # num1 = float(input("Enter first number: "))
35
- # num2 = float(input("Enter second number: "))
36
- # except ValueError:
37
- # print("Invalid input. Please enter numbers.")
38
- # continue
39
- #
40
- # if op == '+':
41
- # result = add(num1, num2)
42
- # elif op == '-':
43
- # result = subtract(num1, num2)
44
- # elif op == '*':
45
- # result = multiply(num1, nu
46
 
47
- # Gradio interface
48
- def process_input(input_text):
49
- try:
50
- # Process the input
51
- return f"Processed: {input_text}"
52
- except Exception as e:
53
- return f"Error: {str(e)}"
54
-
55
- # Create the Gradio app
56
- with gr.Blocks(title="Generated Application", theme=gr.themes.Soft()) as demo:
57
- gr.Markdown("# Generated Application")
58
-
59
- with gr.Row():
60
- with gr.Column():
61
- input_box = gr.Textbox(
62
- label="Input Text",
63
- placeholder="Enter text to process...",
64
- lines=3
65
- )
66
- submit_btn = gr.Button("Process", variant="primary")
67
-
68
- with gr.Row():
69
- output_box = gr.Textbox(
70
- label="Output",
71
- interactive=False,
72
- lines=5
73
- )
74
-
75
- submit_btn.click(
76
- fn=process_input,
77
- inputs=[input_box],
78
- outputs=[output_box]
79
- )
80
 
81
  if __name__ == "__main__":
82
- demo.launch(share=False)
 
1
  import gradio as gr
2
 
3
+ def calculator(num1, op, num2):
4
+ if op == "+":
5
+ result = num1 + num2
6
+ elif op == "-":
7
+ result = num1 - num2
8
+ elif op == "*":
9
+ result = num1 * num2
10
+ elif op == "/":
11
+ if num2 == 0:
12
+ return "Error: Division by zero"
13
+ result = num1 / num2
14
+ else:
15
+ return "Invalid operator"
16
+ return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ demo = gr.Interface(
19
+ calculator,
20
+ [
21
+ gr.Number(label="First Number"),
22
+ gr.Dropdown(label="Operator", choices=["+", "-", "*", "/"]),
23
+ gr.Number(label="Second Number")
24
+ ],
25
+ gr.Textbox(label="Result"),
26
+ title="Simple Calculator",
27
+ description="A simple calculator that performs basic arithmetic operations."
28
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  if __name__ == "__main__":
31
+ demo.launch()