mrbeliever commited on
Commit
c8ade47
·
verified ·
1 Parent(s): 3f1e688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -5,7 +5,7 @@ from openai import OpenAI
5
  # Initialize the Nebius OpenAI client
6
  client = OpenAI(
7
  base_url="https://api.studio.nebius.ai/v1/",
8
- api_key=os.getenv("OPENAI_API_KEY"), # Use the environment variable
9
  )
10
 
11
  # Function to process input and return the response
@@ -23,9 +23,12 @@ def analyze_image(image_url):
23
  max_tokens=300,
24
  )
25
 
26
- # Extract and return the AI's response
27
- return response.choices[0].get("message", {}).get("content", "No response found.")
28
-
 
 
 
29
  except Exception as e:
30
  return f"Error: {str(e)}"
31
 
 
5
  # Initialize the Nebius OpenAI client
6
  client = OpenAI(
7
  base_url="https://api.studio.nebius.ai/v1/",
8
+ api_key=os.getenv("NEBIUS_API_KEY"), # Use the environment variable
9
  )
10
 
11
  # Function to process input and return the response
 
23
  max_tokens=300,
24
  )
25
 
26
+ # Extract the AI response
27
+ if response.choices and "message" in response.choices[0]:
28
+ return response.choices[0]["message"]["content"]
29
+ else:
30
+ return "No valid response received from the API."
31
+
32
  except Exception as e:
33
  return f"Error: {str(e)}"
34