manu commited on
Commit
455a0a2
·
verified ·
1 Parent(s): d4756f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -129,12 +129,10 @@ def index_from_url(url: str) -> Tuple[str, str]:
129
 
130
  def query_gpt(query: str, retrieved_images: list[tuple[Image.Image, str]]) -> str:
131
  """Calls OpenAI's GPT model with the query and image data."""
132
- if api_key and api_key.startswith("sk"):
133
  try:
134
- from openai import OpenAI
135
-
136
  base64_images = [encode_image_to_base64(im_caption[0]) for im_caption in retrieved_images]
137
- client = OpenAI(api_key=api_key.strip())
138
  PROMPT = """
139
  You are a smart assistant designed to answer questions about a PDF document.
140
  You are given relevant information in the form of PDF pages. Use them to construct a short response to the question, and cite your sources (page numbers, etc).
 
129
 
130
  def query_gpt(query: str, retrieved_images: list[tuple[Image.Image, str]]) -> str:
131
  """Calls OpenAI's GPT model with the query and image data."""
132
+ if api_key_env and api_key_env.startswith("sk"):
133
  try:
 
 
134
  base64_images = [encode_image_to_base64(im_caption[0]) for im_caption in retrieved_images]
135
+ client = OpenAI(api_key=api_key_env)
136
  PROMPT = """
137
  You are a smart assistant designed to answer questions about a PDF document.
138
  You are given relevant information in the form of PDF pages. Use them to construct a short response to the question, and cite your sources (page numbers, etc).