akhaliq HF Staff commited on
Commit
195fc5c
·
verified ·
1 Parent(s): 2c3c1bb

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +212 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def calculate(num1, operation, num2):
4
+ """Perform calculation based on selected operation."""
5
+ operations = {
6
+ "➕ Add": lambda a, b: a + b,
7
+ "➖ Subtract": lambda a, b: a - b,
8
+ "✖️ Multiply": lambda a, b: a * b,
9
+ "➗ Divide": lambda a, b: a / b if b != 0 else None
10
+ }
11
+
12
+ if operation == "➗ Divide" and num2 == 0:
13
+ raise gr.Error("Cannot divide by zero!")
14
+
15
+ result = operations[operation](num1, num2)
16
+ return result
17
+
18
+ # Custom CSS for mobile-first, modern design
19
+ custom_css = """
20
+ /* Mobile-first responsive design */
21
+ .calculator-container {
22
+ max-width: 480px;
23
+ margin: 0 auto;
24
+ padding: 1rem;
25
+ }
26
+
27
+ .header-section {
28
+ text-align: center;
29
+ margin-bottom: 2rem;
30
+ }
31
+
32
+ .header-section h1 {
33
+ font-size: clamp(2rem, 5vw, 2.5rem);
34
+ font-weight: 700;
35
+ margin-bottom: 0.5rem;
36
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
37
+ -webkit-background-clip: text;
38
+ -webkit-text-fill-color: transparent;
39
+ background-clip: text;
40
+ }
41
+
42
+ .calculator-card {
43
+ background: rgba(255, 255, 255, 0.05);
44
+ border-radius: 1.5rem;
45
+ padding: 2rem 1.5rem;
46
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
47
+ backdrop-filter: blur(10px);
48
+ }
49
+
50
+ /* Input styling */
51
+ .input-group {
52
+ margin-bottom: 1.5rem;
53
+ }
54
+
55
+ /* Button styling */
56
+ button.primary {
57
+ width: 100%;
58
+ padding: 1rem;
59
+ font-size: 1.125rem;
60
+ font-weight: 600;
61
+ border-radius: 0.75rem;
62
+ transition: all 0.3s ease;
63
+ }
64
+
65
+ button.primary:hover {
66
+ transform: translateY(-2px);
67
+ box-shadow: 0 8px 16px rgba(102, 126, 234, 0.4);
68
+ }
69
+
70
+ /* Result display */
71
+ .result-display {
72
+ font-size: 2rem;
73
+ font-weight: 700;
74
+ text-align: center;
75
+ padding: 1.5rem;
76
+ background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
77
+ border-radius: 1rem;
78
+ margin: 1.5rem 0;
79
+ }
80
+
81
+ /* Examples section */
82
+ .examples-section {
83
+ margin-top: 2rem;
84
+ padding-top: 2rem;
85
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
86
+ }
87
+
88
+ /* Mobile optimization */
89
+ @media (max-width: 640px) {
90
+ .calculator-card {
91
+ padding: 1.5rem 1rem;
92
+ }
93
+
94
+ .header-section h1 {
95
+ font-size: 1.75rem;
96
+ }
97
+ }
98
+
99
+ /* Smooth transitions */
100
+ * {
101
+ transition: all 0.2s ease;
102
+ }
103
+ """
104
+
105
+ with gr.Blocks(fill_height=True) as demo:
106
+ gr.HTML("""
107
+ <div class="header-section">
108
+ <h1>🧮 Calculator</h1>
109
+ <p style="color: #888; font-size: 0.95rem;">
110
+ Simple & elegant calculator built with
111
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder"
112
+ target="_blank"
113
+ style="color: #667eea; text-decoration: none; font-weight: 600;">
114
+ anycoder
115
+ </a>
116
+ </p>
117
+ </div>
118
+ """)
119
+
120
+ with gr.Column(elem_classes="calculator-container"):
121
+ # Input Section
122
+ num1 = gr.Number(
123
+ label="First Number",
124
+ value=0,
125
+ container=True,
126
+ scale=1
127
+ )
128
+
129
+ operation = gr.Radio(
130
+ choices=["➕ Add", "➖ Subtract", "✖️ Multiply", "➗ Divide"],
131
+ value="➕ Add",
132
+ label="Operation",
133
+ container=True
134
+ )
135
+
136
+ num2 = gr.Number(
137
+ label="Second Number",
138
+ value=0,
139
+ container=True,
140
+ scale=1
141
+ )
142
+
143
+ # Calculate Button
144
+ calc_btn = gr.Button(
145
+ "Calculate",
146
+ variant="primary",
147
+ size="lg",
148
+ scale=1
149
+ )
150
+
151
+ # Result Display
152
+ result = gr.Number(
153
+ label="Result",
154
+ interactive=False,
155
+ container=True,
156
+ scale=1,
157
+ show_label=True
158
+ )
159
+
160
+ # Examples Section
161
+ gr.Markdown("### Quick Examples", elem_classes="examples-header")
162
+ gr.Examples(
163
+ examples=[
164
+ [100, "➕ Add", 50],
165
+ [75, "➖ Subtract", 25],
166
+ [12, "✖️ Multiply", 8],
167
+ [144, "➗ Divide", 12],
168
+ ],
169
+ inputs=[num1, operation, num2],
170
+ outputs=result,
171
+ fn=calculate,
172
+ cache_examples=False,
173
+ label=None
174
+ )
175
+
176
+ # Event Handlers
177
+ calc_btn.click(
178
+ fn=calculate,
179
+ inputs=[num1, operation, num2],
180
+ outputs=result,
181
+ api_visibility="public",
182
+ api_name="calculate"
183
+ )
184
+
185
+ # Also trigger on Enter key
186
+ num2.submit(
187
+ fn=calculate,
188
+ inputs=[num1, operation, num2],
189
+ outputs=result
190
+ )
191
+
192
+ if __name__ == "__main__":
193
+ demo.launch(
194
+ theme=gr.themes.Soft(
195
+ primary_hue="indigo",
196
+ secondary_hue="purple",
197
+ neutral_hue="slate",
198
+ font=gr.themes.GoogleFont("Inter"),
199
+ text_size="lg",
200
+ spacing_size="lg",
201
+ radius_size="lg"
202
+ ).set(
203
+ button_primary_background_fill="linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
204
+ button_primary_background_fill_hover="linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%)",
205
+ block_title_text_weight="600",
206
+ block_label_text_weight="500",
207
+ ),
208
+ css=custom_css,
209
+ footer_links=[
210
+ {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
211
+ ]
212
+ )
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=6.0
2
+ requests
3
+ Pillow