Spaces:
Running
Running
updated code
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import datetime
|
|
| 6 |
import sqlite3
|
| 7 |
import base64
|
| 8 |
import os
|
| 9 |
-
|
| 10 |
import json
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
|
|
@@ -107,19 +107,18 @@ def save_record(image, macronutrients, micronutrients, food_items, improvements,
|
|
| 107 |
load_dotenv()
|
| 108 |
|
| 109 |
# Initialize OpenAI API key
|
| 110 |
-
api_key = os.getenv('OPENAI_API_KEY')
|
| 111 |
-
if not api_key:
|
| 112 |
-
st.error("OpenAI API key not
|
| 113 |
st.stop()
|
| 114 |
-
|
| 115 |
# Set the API key directly
|
| 116 |
openai.api_key = api_key
|
| 117 |
|
| 118 |
# Function to analyze image with OpenAI
|
| 119 |
def analyze_image_with_image_recognition(image_bytes):
|
| 120 |
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
| 121 |
-
|
| 122 |
-
response = client.chat.completions.create(
|
| 123 |
model="gpt-4o-mini",
|
| 124 |
messages=[
|
| 125 |
{
|
|
|
|
| 6 |
import sqlite3
|
| 7 |
import base64
|
| 8 |
import os
|
| 9 |
+
import openai
|
| 10 |
import json
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
|
|
|
|
| 107 |
load_dotenv()
|
| 108 |
|
| 109 |
# Initialize OpenAI API key
|
| 110 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 111 |
+
if not openai.api_key:
|
| 112 |
+
st.error("OpenAI API key is not set. Please check your .env file.")
|
| 113 |
st.stop()
|
| 114 |
+
|
| 115 |
# Set the API key directly
|
| 116 |
openai.api_key = api_key
|
| 117 |
|
| 118 |
# Function to analyze image with OpenAI
|
| 119 |
def analyze_image_with_image_recognition(image_bytes):
|
| 120 |
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
| 121 |
+
response = openai.ChatCompletion.create(
|
|
|
|
| 122 |
model="gpt-4o-mini",
|
| 123 |
messages=[
|
| 124 |
{
|