Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Update app.py
Browse files
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
|
8 |
import uuid
|
9 |
import re
|
10 |
|
11 |
# Load environment variables from .env file
|
12 |
load_dotenv()
|
13 |
|
14 |
-
# Initialize OpenAI
|
15 |
-
|
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 =
|
94 |
input=chunks,
|
95 |
model=EMBEDDING_MODEL
|
96 |
)
|
97 |
-
embeddings = [
|
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(
|