Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -3,6 +3,7 @@ import fitz # PyMuPDF
|
|
3 |
from transformers import pipeline
|
4 |
from datetime import datetime
|
5 |
|
|
|
6 |
st.set_page_config(page_title="Health Report Analyzer", page_icon="🩺")
|
7 |
st.title("🩺 Health Report Analyzer")
|
8 |
|
@@ -17,14 +18,14 @@ def extract_text(file):
|
|
17 |
text += page.get_text()
|
18 |
return text
|
19 |
|
20 |
-
# Load
|
21 |
@st.cache_resource
|
22 |
def load_models():
|
23 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
24 |
explainer = pipeline("text2text-generation", model="google/flan-t5-base")
|
25 |
return summarizer, explainer
|
26 |
|
27 |
-
#
|
28 |
if uploaded_file:
|
29 |
text_data = extract_text(uploaded_file)
|
30 |
st.success("PDF Text Extracted Successfully!")
|
@@ -49,11 +50,12 @@ if uploaded_file:
|
|
49 |
st.subheader("Explanation")
|
50 |
st.write(explanation)
|
51 |
|
|
|
52 |
st.session_state['summary'] = summary
|
53 |
st.session_state['explanation'] = explanation
|
54 |
|
55 |
-
# Chatbot
|
56 |
-
st.subheader("AI Chatbot: Ask Anything About Your Report or Medical Terms")
|
57 |
|
58 |
if 'summary' in st.session_state and 'explanation' in st.session_state:
|
59 |
user_question = st.text_input("Ask a question (e.g. 'meaning of CT scan', 'explain cholecystectomy'):")
|
@@ -72,11 +74,8 @@ if uploaded_file:
|
|
72 |
|
73 |
st.success("AI's Response:")
|
74 |
st.write(response)
|
75 |
-
|
76 |
else:
|
77 |
-
st.info("
|
78 |
|
79 |
else:
|
80 |
st.info("Upload a PDF Health Report to begin.")
|
81 |
-
|
82 |
-
|
|
|
3 |
from transformers import pipeline
|
4 |
from datetime import datetime
|
5 |
|
6 |
+
# Streamlit page setup
|
7 |
st.set_page_config(page_title="Health Report Analyzer", page_icon="🩺")
|
8 |
st.title("🩺 Health Report Analyzer")
|
9 |
|
|
|
18 |
text += page.get_text()
|
19 |
return text
|
20 |
|
21 |
+
# Load models from HuggingFace
|
22 |
@st.cache_resource
|
23 |
def load_models():
|
24 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
25 |
explainer = pipeline("text2text-generation", model="google/flan-t5-base")
|
26 |
return summarizer, explainer
|
27 |
|
28 |
+
# Main logic
|
29 |
if uploaded_file:
|
30 |
text_data = extract_text(uploaded_file)
|
31 |
st.success("PDF Text Extracted Successfully!")
|
|
|
50 |
st.subheader("Explanation")
|
51 |
st.write(explanation)
|
52 |
|
53 |
+
# Store in session
|
54 |
st.session_state['summary'] = summary
|
55 |
st.session_state['explanation'] = explanation
|
56 |
|
57 |
+
# AI Chatbot
|
58 |
+
st.subheader("💬 AI Chatbot: Ask Anything About Your Report or Medical Terms")
|
59 |
|
60 |
if 'summary' in st.session_state and 'explanation' in st.session_state:
|
61 |
user_question = st.text_input("Ask a question (e.g. 'meaning of CT scan', 'explain cholecystectomy'):")
|
|
|
74 |
|
75 |
st.success("AI's Response:")
|
76 |
st.write(response)
|
|
|
77 |
else:
|
78 |
+
st.info("Please generate the summary and explanation first to enable the chatbot.")
|
79 |
|
80 |
else:
|
81 |
st.info("Upload a PDF Health Report to begin.")
|
|
|
|