Ifeanyi commited on
Commit
81ce9aa
·
verified ·
1 Parent(s): 7d84cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -68
app.py CHANGED
@@ -12,84 +12,99 @@ robj.r("""
12
  """)
13
 
14
  def arithmetic(num1, num2, operation):
15
-
16
- with localconverter(default_converter):
 
 
 
 
 
 
 
 
17
 
18
- if operation == "Add":
19
- res = robj.r(f"add({num1}, {num2})")
20
- elif operation == "Multiply":
21
- res = robj.r(f"multiply({num1}, {num2})")
22
- elif operation == "Subtract":
23
- res = robj.r(f"sub({num1}, {num2})")
24
- elif operation == "Divide":
25
- res = robj.r(f"div({num1}, {num2})")
26
 
27
- return res[0]
 
 
 
 
 
 
 
28
 
29
- custom_css = """
30
- /* Dark background and light text */
31
- body {
32
- background-color: #121212;
33
- color: #ffffff;
34
- }
35
-
36
- /* Make inputs visible on dark background */
37
- input, textarea, select {
38
- background-color: #2a2a2a;
39
- color: #ffffff;
40
- border: 1px solid #444;
41
- }
42
-
43
- /* Simple gradient button */
44
- button {
45
- background: linear-gradient(135deg, #4568dc, #0f4c81);
46
- color: white;
47
- }
48
-
49
- /* Ensure result is visible */
50
- #result, .output-class, .gr-number-output {
51
- color: white; !important
52
- font-size: large;
53
- }
54
-
55
- /* Hide footer */
56
- footer {
57
- display: none;!important;
58
- }
 
 
 
 
 
 
 
 
59
  """
 
60
  with gr.Blocks(
61
  title="R-Powered Calculator",
62
  theme=gr.themes.Base(),
63
- css = custom_css
64
  ) as app:
65
- gr.HTML(
66
- """
67
- <h1 style='text-align: center'>
68
- <strong>R-Powered Calculator</strong>
69
- </h1>
70
- """
71
- )
72
- with gr.Row():
73
- num1 = gr.Number(label="Number 1")
74
- num2 = gr.Number(label="Number 2")
75
- with gr.Column():
76
- operation = gr.Radio(choices=["Add", "Multiply", "Subtract", "Divide"],
77
- value="Add",
78
- label="Choose Arithmetic Operation",
79
- min_width=100,
80
- scale=0.3)
81
- with gr.Row():
82
- submit = gr.Button("Run Operation")
83
- with gr.Column():
84
  gr.HTML(
85
- """
86
- <h3 style='text-align: center'>
87
- <strong>Arithmetic Operation Result</strong>
88
- </h3>
89
- """
90
  )
91
- result = gr.Number()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- submit.click(arithmetic, inputs=[num1, num2, operation], outputs=[result])
94
 
95
  app.launch(server_name="0.0.0.0", server_port=7860)
 
12
  """)
13
 
14
  def arithmetic(num1, num2, operation):
15
+ with localconverter(default_converter):
16
+ if operation == "Add":
17
+ res = robj.r(f"add({num1}, {num2})")
18
+ elif operation == "Multiply":
19
+ res = robj.r(f"multiply({num1}, {num2})")
20
+ elif operation == "Subtract":
21
+ res = robj.r(f"sub({num1}, {num2})")
22
+ elif operation == "Divide":
23
+ res = robj.r(f"div({num1}, {num2})")
24
+ return res[0]
25
 
26
+ # Custom CSS for better theme
27
+ custom_css = """
28
+ body {
29
+ background-color: #121212;
30
+ color: #ffffff;
31
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
32
+ }
 
33
 
34
+ /* Inputs and selects */
35
+ input, textarea, select {
36
+ background-color: #1e1e1e;
37
+ color: #ffffff;
38
+ border: 1px solid #555;
39
+ border-radius: 6px;
40
+ padding: 8px;
41
+ }
42
 
43
+ /* Radio buttons */
44
+ label input[type="radio"] {
45
+ accent-color: #3b82f6;
46
+ }
47
+
48
+ /* Buttons */
49
+ button {
50
+ background: linear-gradient(135deg, #3b82f6, #0f4c81);
51
+ color: white;
52
+ border: none;
53
+ border-radius: 6px;
54
+ padding: 10px 20px;
55
+ cursor: pointer;
56
+ transition: background 0.3s ease;
57
+ }
58
+ button:hover {
59
+ background: linear-gradient(135deg, #60a5fa, #2563eb);
60
+ }
61
+
62
+ /* Result field styling */
63
+ #result input {
64
+ background-color: #1e1e1e;
65
+ color: #00ffcc;
66
+ font-size: 1.5em;
67
+ border: 1px solid #444;
68
+ text-align: center;
69
+ }
70
+
71
+ /* Center heading text */
72
+ h1, h3 {
73
+ text-align: center;
74
+ color: #ffffff;
75
+ }
76
+
77
+ /* Hide footer */
78
+ footer {
79
+ display: none !important;
80
+ }
81
  """
82
+
83
  with gr.Blocks(
84
  title="R-Powered Calculator",
85
  theme=gr.themes.Base(),
86
+ css=custom_css
87
  ) as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  gr.HTML(
89
+ "<h1><strong>R-Powered Calculator</strong></h1>"
 
 
 
 
90
  )
91
+ with gr.Row():
92
+ num1 = gr.Number(label="Number 1")
93
+ num2 = gr.Number(label="Number 2")
94
+ with gr.Column():
95
+ operation = gr.Radio(
96
+ choices=["Add", "Multiply", "Subtract", "Divide"],
97
+ value="Add",
98
+ label="Choose Arithmetic Operation",
99
+ min_width=100,
100
+ scale=0.3
101
+ )
102
+ with gr.Row():
103
+ submit = gr.Button("Run Operation")
104
+ with gr.Column():
105
+ gr.HTML("<h2><strong>Arithmetic Operation Result</strong></h2>")
106
+ result = gr.Number(elem_id="result")
107
 
108
+ submit.click(arithmetic, inputs=[num1, num2, operation], outputs=[result])
109
 
110
  app.launch(server_name="0.0.0.0", server_port=7860)