Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,23 +87,18 @@ def api_submit_answers(processed_answers: List[Dict[str, str]]) -> Dict[str, Any
|
|
| 87 |
return {}
|
| 88 |
|
| 89 |
# --- OpenAI Client Configuration ---
|
| 90 |
-
|
| 91 |
-
if not OPENAI_API_KEY_VALUE:
|
| 92 |
-
print("OPENAI_API_KEY not found in environment variables. Attempting to load from a local .env file...")
|
| 93 |
-
load_dotenv()
|
| 94 |
OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
client = None
|
| 100 |
-
else:
|
| 101 |
-
try:
|
| 102 |
-
client = OpenAI(api_key=OPENAI_API_KEY_VALUE)
|
| 103 |
-
print("OpenAI client initialized successfully.")
|
| 104 |
-
except Exception as e:
|
| 105 |
-
print(f"Error initializing OpenAI client: {e}")
|
| 106 |
-
client = None
|
| 107 |
|
| 108 |
LLM_MODEL = "gpt-3.5-turbo"
|
| 109 |
|
|
|
|
| 87 |
return {}
|
| 88 |
|
| 89 |
# --- OpenAI Client Configuration ---
|
| 90 |
+
try:
|
|
|
|
|
|
|
|
|
|
| 91 |
OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
|
| 92 |
+
if not OPENAI_API_KEY_VALUE:
|
| 93 |
+
raise ValueError("OPENAI_API_KEY not found in environment variables")
|
| 94 |
+
|
| 95 |
+
# Initialize OpenAI client with minimal configuration
|
| 96 |
+
client = OpenAI(api_key=OPENAI_API_KEY_VALUE)
|
| 97 |
+
print("OpenAI client initialized successfully.")
|
| 98 |
+
except Exception as e:
|
| 99 |
+
print(f"Error initializing OpenAI client: {str(e)}")
|
| 100 |
+
print("Please ensure OPENAI_API_KEY is properly set in Hugging Face Space secrets")
|
| 101 |
client = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
LLM_MODEL = "gpt-3.5-turbo"
|
| 104 |
|