Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,10 @@ processor = AutoImageProcessor.from_pretrained(MODEL_NAME)
|
|
| 19 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "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")
|
| 20 |
client = Groq(api_key=GROQ_API_KEY)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Function to predict skin disease
|
| 23 |
def predict_skin_disease(image):
|
| 24 |
image = image.convert("RGB")
|
|
@@ -35,7 +39,7 @@ def predict_skin_disease(image):
|
|
| 35 |
|
| 36 |
# Function to get disease details from Groq API
|
| 37 |
def get_disease_info(disease_name):
|
| 38 |
-
prompt = f"Provide a detailed explanation about the skin disease '{disease_name}', including
|
| 39 |
|
| 40 |
chat_completion = client.chat.completions.create(
|
| 41 |
messages=[{"role": "user", "content": prompt}],
|
|
@@ -46,6 +50,9 @@ def get_disease_info(disease_name):
|
|
| 46 |
|
| 47 |
# Function to handle chatbot queries
|
| 48 |
def chatbot_response(disease_name, user_query):
|
|
|
|
|
|
|
|
|
|
| 49 |
prompt = f"The detected skin disease is '{disease_name}'. {user_query}"
|
| 50 |
|
| 51 |
chat_completion = client.chat.completions.create(
|
|
@@ -65,11 +72,12 @@ uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]
|
|
| 65 |
|
| 66 |
if uploaded_image:
|
| 67 |
image = Image.open(uploaded_image)
|
| 68 |
-
st.image(image, caption="Uploaded Image",
|
| 69 |
|
| 70 |
if st.button("Detect Disease"):
|
| 71 |
with st.spinner("Analyzing..."):
|
| 72 |
disease_name = predict_skin_disease(image)
|
|
|
|
| 73 |
disease_info = get_disease_info(disease_name)
|
| 74 |
st.success(f"**Detected Disease:** {disease_name}")
|
| 75 |
st.write(f"**Details:** {disease_info}")
|
|
@@ -79,13 +87,9 @@ st.subheader("💬 Ask DermaBot")
|
|
| 79 |
user_query = st.text_input("Ask about the detected disease:")
|
| 80 |
|
| 81 |
if st.button("Ask"):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
st.write(response)
|
| 86 |
-
else:
|
| 87 |
-
st.warning("Please upload an image first.")
|
| 88 |
|
| 89 |
st.markdown("---")
|
| 90 |
st.write("🔍 Powered by **AI & Groq API** | © 2025 DermaBot")
|
| 91 |
-
|
|
|
|
| 19 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY", "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")
|
| 20 |
client = Groq(api_key=GROQ_API_KEY)
|
| 21 |
|
| 22 |
+
# Initialize session state for disease_name
|
| 23 |
+
if "disease_name" not in st.session_state:
|
| 24 |
+
st.session_state.disease_name = None
|
| 25 |
+
|
| 26 |
# Function to predict skin disease
|
| 27 |
def predict_skin_disease(image):
|
| 28 |
image = image.convert("RGB")
|
|
|
|
| 39 |
|
| 40 |
# Function to get disease details from Groq API
|
| 41 |
def get_disease_info(disease_name):
|
| 42 |
+
prompt = f"Provide a detailed explanation about the skin disease '{disease_name}', including causes, symptoms, and treatment options."
|
| 43 |
|
| 44 |
chat_completion = client.chat.completions.create(
|
| 45 |
messages=[{"role": "user", "content": prompt}],
|
|
|
|
| 50 |
|
| 51 |
# Function to handle chatbot queries
|
| 52 |
def chatbot_response(disease_name, user_query):
|
| 53 |
+
if not disease_name:
|
| 54 |
+
return "Please upload an image and detect the disease first."
|
| 55 |
+
|
| 56 |
prompt = f"The detected skin disease is '{disease_name}'. {user_query}"
|
| 57 |
|
| 58 |
chat_completion = client.chat.completions.create(
|
|
|
|
| 72 |
|
| 73 |
if uploaded_image:
|
| 74 |
image = Image.open(uploaded_image)
|
| 75 |
+
st.image(image, caption="Uploaded Image", use_container_width=True) # Fixed the warning
|
| 76 |
|
| 77 |
if st.button("Detect Disease"):
|
| 78 |
with st.spinner("Analyzing..."):
|
| 79 |
disease_name = predict_skin_disease(image)
|
| 80 |
+
st.session_state.disease_name = disease_name # Store in session state
|
| 81 |
disease_info = get_disease_info(disease_name)
|
| 82 |
st.success(f"**Detected Disease:** {disease_name}")
|
| 83 |
st.write(f"**Details:** {disease_info}")
|
|
|
|
| 87 |
user_query = st.text_input("Ask about the detected disease:")
|
| 88 |
|
| 89 |
if st.button("Ask"):
|
| 90 |
+
with st.spinner("Thinking..."):
|
| 91 |
+
response = chatbot_response(st.session_state.disease_name, user_query)
|
| 92 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
st.markdown("---")
|
| 95 |
st.write("🔍 Powered by **AI & Groq API** | © 2025 DermaBot")
|
|
|