Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 7 |
|
| 8 |
# =======================
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 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
|
| 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 |
"""
|