Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
import os
|
4 |
|
5 |
-
# OpenAI API
|
6 |
api_key = os.getenv("OPENAI_API_KEY")
|
7 |
client = openai.OpenAI(api_key=api_key)
|
8 |
|
@@ -10,7 +10,7 @@ def ai_calculator(num1, num2, operation):
|
|
10 |
if not api_key:
|
11 |
return "❌ OpenAI API key not set."
|
12 |
|
13 |
-
prompt = f"
|
14 |
|
15 |
try:
|
16 |
response = client.chat.completions.create(
|
@@ -32,11 +32,11 @@ demo = gr.Interface(
|
|
32 |
inputs=[
|
33 |
gr.Number(label="Enter First Number"),
|
34 |
gr.Number(label="Enter Second Number"),
|
35 |
-
gr.Radio(["
|
36 |
],
|
37 |
outputs="text",
|
38 |
title="🧠 AI Calculator",
|
39 |
-
description="A simple calculator using OpenAI GPT-3.5.
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|
|
|
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 |
|
|
|
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 |
response = client.chat.completions.create(
|
|
|
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="🧠 AI Calculator",
|
39 |
+
description="A simple calculator using OpenAI GPT-3.5 Turbo. Enter numbers and choose operation.",
|
40 |
)
|
41 |
|
42 |
if __name__ == "__main__":
|