abdullahrehan's picture
Update app.py
7c31bf8 verified
import streamlit as st
import os
from groq import Groq
# Load GROQ API key from Hugging Face Secrets
api_key = os.getenv("GROQ_API_KEY")
if not api_key:
st.error("GROQ_API_KEY is not set. Please add it in the Hugging Face Secrets.")
st.stop()
# GROQ client
client = Groq(api_key=api_key)
# Function to ask GROQ model
def ask_groq(symptoms):
prompt = (
f"A user reports the following symptoms: {symptoms}. "
"Suggest a few possible common conditions in friendly language. "
"Clearly mention it's not a diagnosis. Keep it simple and helpful."
)
response = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
# Streamlit UI
st.set_page_config(page_title="AI Symptom Checker", page_icon="🩺", layout="centered")
st.title("🩺 AI Symptom Checker")
st.write("Describe your symptoms below. This tool will suggest possible conditions in an educational, non-diagnostic way.")
# Input field
symptoms = st.text_area("Your symptoms", height=150, placeholder="e.g., sore throat, mild fever, body aches...")
# Submit button
if st.button("Check Symptoms"):
if symptoms.strip():
with st.spinner("Thinking..."):
result = ask_groq(symptoms)
st.subheader("🧠 AI Suggestion")
st.write(result)
else:
st.warning("Please enter your symptoms to continue.")