Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
import openai
|
3 |
-
import os
|
4 |
-
|
5 |
-
# OpenAI API key (from Hugging Face secrets)
|
6 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
7 |
-
client = openai.OpenAI(api_key=api_key)
|
8 |
-
|
9 |
-
def ai_calculator(num1, num2, operation):
|
10 |
-
if not api_key:
|
11 |
-
return "β OpenAI API key not set."
|
12 |
-
|
13 |
-
prompt = f"Calculate {num1} {operation} {num2} and return the result only."
|
14 |
|
|
|
15 |
try:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
return f"β
Result: {result}"
|
27 |
except Exception as e:
|
28 |
return f"β Error: {str(e)}"
|
29 |
|
30 |
demo = gr.Interface(
|
31 |
-
fn=
|
32 |
inputs=[
|
33 |
gr.Number(label="Enter First Number"),
|
34 |
gr.Number(label="Enter Second Number"),
|
35 |
gr.Radio(["+", "-", "*", "/"], label="Operation"),
|
36 |
],
|
37 |
outputs="text",
|
38 |
-
title="π§
|
39 |
-
description="
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
def simple_calculator(num1, num2, operation):
|
4 |
try:
|
5 |
+
if operation == "+":
|
6 |
+
result = num1 + num2
|
7 |
+
elif operation == "-":
|
8 |
+
result = num1 - num2
|
9 |
+
elif operation == "*":
|
10 |
+
result = num1 * num2
|
11 |
+
elif operation == "/":
|
12 |
+
result = num1 / num2 if num2 != 0 else "β (Divide by Zero)"
|
13 |
+
else:
|
14 |
+
result = "Unknown operation"
|
15 |
return f"β
Result: {result}"
|
16 |
except Exception as e:
|
17 |
return f"β Error: {str(e)}"
|
18 |
|
19 |
demo = gr.Interface(
|
20 |
+
fn=simple_calculator,
|
21 |
inputs=[
|
22 |
gr.Number(label="Enter First Number"),
|
23 |
gr.Number(label="Enter Second Number"),
|
24 |
gr.Radio(["+", "-", "*", "/"], label="Operation"),
|
25 |
],
|
26 |
outputs="text",
|
27 |
+
title="π§ Simple Calculator (No OpenAI)",
|
28 |
+
description="This is a temporary calculator while you cry over OpenAI quota π’",
|
29 |
)
|
30 |
|
31 |
if __name__ == "__main__":
|