asad231 commited on
Commit
64178de
·
verified ·
1 Parent(s): 057b027

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import openai
3
  import os
4
 
5
- # OpenAI API setup
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"Perform {operation} operation on {num1} and {num2}. Just return the result only."
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(["add", "subtract", "multiply", "divide"], label="Operation"),
36
  ],
37
  outputs="text",
38
  title="🧠 AI Calculator",
39
- description="A simple calculator using OpenAI GPT-3.5. Choose numbers and operation to get result.",
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__":