CoolFace
Apppublic

vidya7732/AI_Doctor_LLM_GenModel

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
app.py55 linesDownload Raw Back to root
1import streamlit as st
2from langchain_groq import ChatGroq
3from langchain_core.prompts import PromptTemplate
4from dotenv import load_dotenv
5import os
6
7# ----------------------------
8# 1️⃣ Load API Key Securely
9# ----------------------------
10load_dotenv()
11groq_api_key = os.getenv("GROQ_API_KEY")
12
13# ----------------------------
14# 2️⃣ Streamlit Setup
15# ----------------------------
16st.set_page_config(page_title="AI Doctor 💊", page_icon="💉")
17st.title("💊 AI DOCTOR - Quick Health Suggestion")
18st.write("🤖 Enter your symptoms below to get a **2-line quick diagnosis.**")
19
20# ----------------------------
21# 3️⃣ User Input
22# ----------------------------
23AA = st.text_area("🧬 Enter your Symptoms:", placeholder="e.g. headache, fever, body pain...")
24submit = st.button("🔍 Get Suggestion")
25
26# ----------------------------
27# 4️⃣ Model & Logic
28# ----------------------------
29if not groq_api_key:
30    st.error("❌ API Key not found! Please check your .env file.")
31elif submit:
32    if not AA.strip():
33        st.warning("⚠️ Please enter your symptoms before submitting.")
34    else:
35        with st.spinner("🧠 Analyzing your symptoms..."):
36            try:
37                model = ChatGroq(
38                    temperature=0.4,
39                    groq_api_key=groq_api_key,
40                    model_name="llama-3.1-8b-instant"  # ⚡️ Faster & cheaper model
41                )
42
43                prompt = PromptTemplate(
44                    input_variables=["X"],
45                    template="I am having {X}. In exactly 2 short lines, give cause and treatment."
46                )
47
48                query = prompt.format(X=AA)
49                response = model.invoke(query)
50                st.success("💬 **AI Doctor Quick Suggestion:**")
51                st.write(response.content)
52
53            except Exception as e:
54                st.error(f"❌ Error: {e}")
55