Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,84 +12,99 @@ robj.r("""
|
|
12 |
""")
|
13 |
|
14 |
def arithmetic(num1, num2, operation):
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
res = robj.r(f"div({num1}, {num2})")
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
"""
|
|
|
60 |
with gr.Blocks(
|
61 |
title="R-Powered Calculator",
|
62 |
theme=gr.themes.Base(),
|
63 |
-
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
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)
|