mgbam commited on
Commit
5b2305a
·
verified ·
1 Parent(s): 3300549

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -3,10 +3,23 @@ from transformers import pipeline, AutoModelForImageClassification, AutoFeatureE
3
  from PIL import Image
4
  import openai
5
  import os
6
- import torch
7
 
8
  # =======================
9
- # Streamlit Page Config (MUST BE FIRST)
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # =======================
11
  st.set_page_config(
12
  page_title="AI-Powered Skin Cancer Detection",
@@ -16,12 +29,7 @@ st.set_page_config(
16
  )
17
 
18
  # =======================
19
- # OpenAI API Configuration
20
- # =======================
21
- openai.api_key = os.getenv("OPENAI_API_KEY", "your_openai_api_key_here")
22
-
23
- # =======================
24
- # Load Model with PyTorch
25
  # =======================
26
  @st.cache_resource
27
  def load_model():
@@ -40,7 +48,7 @@ def load_model():
40
  model = load_model()
41
 
42
  # =======================
43
- # OpenAI Explanation Function
44
  # =======================
45
  def generate_openai_explanation(label, confidence):
46
  """
 
3
  from PIL import Image
4
  import openai
5
  import os
6
+ from dotenv import load_dotenv
7
 
8
  # =======================
9
+ # Load Environment Variables from .env File
10
+ # =======================
11
+ load_dotenv() # Explicitly load the .env file
12
+
13
+ # Set OpenAI API key
14
+ openai.api_key = os.getenv("OPENAI_API_KEY")
15
+
16
+ # Debugging: Check if API key is loaded
17
+ if not openai.api_key or not openai.api_key.startswith("sk-"):
18
+ st.error("OpenAI API key is not set or is invalid. Please check the `.env` file or your environment variable setup.")
19
+ st.stop()
20
+
21
+ # =======================
22
+ # Streamlit Page Config
23
  # =======================
24
  st.set_page_config(
25
  page_title="AI-Powered Skin Cancer Detection",
 
29
  )
30
 
31
  # =======================
32
+ # Load Skin Cancer Model (PyTorch)
 
 
 
 
 
33
  # =======================
34
  @st.cache_resource
35
  def load_model():
 
48
  model = load_model()
49
 
50
  # =======================
51
+ # Generate OpenAI Explanation
52
  # =======================
53
  def generate_openai_explanation(label, confidence):
54
  """