poemsforaphrodite commited on
Commit
81c2749
·
verified ·
1 Parent(s): 03ccacf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -4,15 +4,15 @@ import io
4
  import os
5
  from dotenv import load_dotenv
6
  from pinecone import Pinecone, ServerlessSpec
7
- import openai
8
  import uuid
9
  import re
10
 
11
  # Load environment variables from .env file
12
  load_dotenv()
13
 
14
- # Initialize OpenAI API
15
- openai.api_key = os.getenv("OPENAI_API_KEY")
16
 
17
  # Initialize Pinecone
18
  PINECONE_API_KEY = os.getenv("PINECONE_API_KEY")
@@ -90,11 +90,11 @@ def get_embeddings(chunks):
90
  """
91
  Generates embeddings for each chunk using OpenAI's embedding API.
92
  """
93
- response = openai.Embedding.create(
94
  input=chunks,
95
  model=EMBEDDING_MODEL
96
  )
97
- embeddings = [record['embedding'] for record in response['data']]
98
  return embeddings
99
 
100
  iface = gr.Interface(
 
4
  import os
5
  from dotenv import load_dotenv
6
  from pinecone import Pinecone, ServerlessSpec
7
+ from openai import OpenAI
8
  import uuid
9
  import re
10
 
11
  # Load environment variables from .env file
12
  load_dotenv()
13
 
14
+ # Initialize OpenAI client
15
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
16
 
17
  # Initialize Pinecone
18
  PINECONE_API_KEY = os.getenv("PINECONE_API_KEY")
 
90
  """
91
  Generates embeddings for each chunk using OpenAI's embedding API.
92
  """
93
+ response = client.embeddings.create(
94
  input=chunks,
95
  model=EMBEDDING_MODEL
96
  )
97
+ embeddings = [data.embedding for data in response.data]
98
  return embeddings
99
 
100
  iface = gr.Interface(