bstraehle commited on
Commit
39b2ad4
1 Parent(s): c35a445

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -26,10 +26,13 @@ from assistants import (
26
  )
27
 
28
  def chat(message, history, openai_api_key):
 
 
29
  if not message:
30
  raise gr.Error("Message is required.")
31
 
32
  #raise gr.Error("Please clone and bring your own credentials.")
 
33
 
34
  global assistant, thread
35
 
@@ -58,6 +61,8 @@ def chat(message, history, openai_api_key):
58
  if len(image_values) > 0:
59
  download_link = f"<hr>[Download](https://platform.openai.com/storage/files/{image_values[0]})"
60
 
 
 
61
  #return f"{'<hr>'.join(list(reversed(text_values))[1:])}{download_link}"
62
  return f"{text_values[0]}{download_link}"
63
 
 
26
  )
27
 
28
  def chat(message, history, openai_api_key):
29
+ if not openai_api_key:
30
+ raise gr.Error("OpenAI API Key is required.")
31
  if not message:
32
  raise gr.Error("Message is required.")
33
 
34
  #raise gr.Error("Please clone and bring your own credentials.")
35
+ os.environ["OPENAI_API_KEY"] = openai_api_key
36
 
37
  global assistant, thread
38
 
 
61
  if len(image_values) > 0:
62
  download_link = f"<hr>[Download](https://platform.openai.com/storage/files/{image_values[0]})"
63
 
64
+ del os.environ["OPENAI_API_KEY"]
65
+
66
  #return f"{'<hr>'.join(list(reversed(text_values))[1:])}{download_link}"
67
  return f"{text_values[0]}{download_link}"
68