navkrishna commited on
Commit
0815b5a
·
1 Parent(s): 006bcf6

udpated app.py with new calc code

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,7 +1,23 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text here")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ def calculator(input_str):
4
+ try:
5
+ result = eval(input_str)
6
+ return result
7
+ except ZeroDivisionError:
8
+ return "Division by zero error"
9
+ except Exception as e:
10
+ return f"Error: {str(e)}"
11
 
12
+ # Create the Gradio interface
13
+ interface = gr.Interface(
14
+ fn=calculator,
15
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter calculation (e.g., 3 + 5 * 2)", label="Calculator Input"),
16
+ outputs="text",
17
+ title="Simple Calculator",
18
+ description="Enter a mathematical expression to calculate the result."
19
+ )
20
+
21
+ # Launch the app
22
+ if __name__ == "__main__":
23
+ interface.launch()