Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +45 -0
- requirements.txt +0 -0
- temp.pdf +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
temp.pdf filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import fitz # PyMuPDF
|
2 |
+
import google.generativeai as genai
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
def extract_text_from_pdf(pdf_path):
|
6 |
+
"""Extracts text from a PDF file."""
|
7 |
+
text = ""
|
8 |
+
try:
|
9 |
+
with fitz.open(pdf_path) as doc:
|
10 |
+
for page in doc:
|
11 |
+
text += page.get_text("text") + "\n"
|
12 |
+
except Exception as e:
|
13 |
+
st.error(f"Error reading PDF: {e}")
|
14 |
+
return text
|
15 |
+
|
16 |
+
def analyze_health_data(text):
|
17 |
+
"""Analyzes extracted text using Google Generative AI (Free Tier API)."""
|
18 |
+
try:
|
19 |
+
# Get a free API key from Google AI Studio: https://aistudio.google.com/
|
20 |
+
genai.configure(api_key="AIzaSyAY6ZYxOzVV5N7mBZzDJ96WEPJGfuFx-mU") # Replace with free API key
|
21 |
+
model = genai.GenerativeModel("gemini-pro") # Choose appropriate model
|
22 |
+
response = model.generate_content(
|
23 |
+
f"Analyze this blood report and provide trends, risks, and health suggestions:\n{text}"
|
24 |
+
)
|
25 |
+
return response.text
|
26 |
+
except Exception as e:
|
27 |
+
return f"Error in LLM response: {e}"
|
28 |
+
|
29 |
+
def main():
|
30 |
+
st.title("Health Report Analyzer")
|
31 |
+
uploaded_file = st.file_uploader("Upload your health report (PDF)", type=["pdf"])
|
32 |
+
if uploaded_file is not None:
|
33 |
+
with open("temp.pdf", "wb") as f:
|
34 |
+
f.write(uploaded_file.getbuffer())
|
35 |
+
extracted_text = extract_text_from_pdf("temp.pdf")
|
36 |
+
st.subheader("Extracted Report Text:")
|
37 |
+
st.text_area("Extracted Text", extracted_text[:1000], height=200)
|
38 |
+
if st.button("Analyze Report"):
|
39 |
+
with st.spinner("Analyzing..."):
|
40 |
+
analysis = analyze_health_data(extracted_text)
|
41 |
+
st.subheader("Health Analysis:")
|
42 |
+
st.write(analysis)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
main()
|
requirements.txt
ADDED
File without changes
|
temp.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:12f1b9afdb66003daa060c3c31c72f62759b3a62fccdcfc4d312047a867c7cd4
|
3 |
+
size 309139
|