Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from utils import extract_text_from_image, speech_to_text
|
| 4 |
+
from ml_model import predict_common_diseases
|
| 5 |
+
from rag_helper import build_knowledge_base, get_medical_guidance
|
| 6 |
+
|
| 7 |
+
st.set_page_config(page_title="π GenAI Drug Finder", layout="centered")
|
| 8 |
+
st.title("π GenAI Drug Finder & AI Health Guide")
|
| 9 |
+
|
| 10 |
+
# Load data
|
| 11 |
+
medicine_df = pd.read_csv("data/medicine_data.csv")
|
| 12 |
+
kb_index, kb_texts, kb_files = build_knowledge_base("data/medical_guides")
|
| 13 |
+
|
| 14 |
+
# Search medicine
|
| 15 |
+
st.header("π Search for Medicine")
|
| 16 |
+
method = st.radio("Choose Input Method", ["Text Search", "Upload Prescription", "Voice Search"])
|
| 17 |
+
|
| 18 |
+
query = ""
|
| 19 |
+
|
| 20 |
+
if method == "Text Search":
|
| 21 |
+
query = st.text_input("Enter medicine name")
|
| 22 |
+
elif method == "Upload Prescription":
|
| 23 |
+
file = st.file_uploader("Upload prescription image", type=["png", "jpg", "jpeg"])
|
| 24 |
+
if file:
|
| 25 |
+
query = extract_text_from_image(file)
|
| 26 |
+
st.success(f"Extracted text: {query}")
|
| 27 |
+
elif method == "Voice Search":
|
| 28 |
+
st.info("Click to record from mic (for local testing only)")
|
| 29 |
+
if st.button("π€ Start Recording"):
|
| 30 |
+
query = speech_to_text()
|
| 31 |
+
st.success(f"You said: {query}")
|
| 32 |
+
|
| 33 |
+
if query:
|
| 34 |
+
results = medicine_df[medicine_df['medicine_name'].str.contains(query, case=False, na=False)]
|
| 35 |
+
if not results.empty:
|
| 36 |
+
st.subheader("π Matching Medicines")
|
| 37 |
+
st.dataframe(results)
|
| 38 |
+
else:
|
| 39 |
+
st.warning("Medicine not found in inventory.")
|
| 40 |
+
|
| 41 |
+
# Predict diseases
|
| 42 |
+
st.header("π Predict Common Diseases in Area")
|
| 43 |
+
if st.button("π Analyze Billing Data"):
|
| 44 |
+
top_diseases = predict_common_diseases("data/billing_data.csv")
|
| 45 |
+
st.success("Top Diseases:")
|
| 46 |
+
for disease in top_diseases:
|
| 47 |
+
st.markdown(f"β
{disease}")
|
| 48 |
+
|
| 49 |
+
# RAG Guidance
|
| 50 |
+
st.header("π§ AI Health Assistant")
|
| 51 |
+
disease_input = st.selectbox("Select or type a disease", ["diabetes", "cold", "fever", "other"])
|
| 52 |
+
custom_input = ""
|
| 53 |
+
if disease_input == "other":
|
| 54 |
+
custom_input = st.text_input("Enter disease name")
|
| 55 |
+
|
| 56 |
+
selected_disease = custom_input if disease_input == "other" else disease_input
|
| 57 |
+
|
| 58 |
+
if selected_disease:
|
| 59 |
+
guidance = get_medical_guidance(selected_disease, kb_index, kb_texts)
|
| 60 |
+
st.subheader("π Medical Guidance")
|
| 61 |
+
st.write(guidance)
|