mdasad3617's picture
Update app.py
7f334ec verified
raw
history blame
2.34 kB
import streamlit as st
from models import initialize_models
from models.pdf_handler import parse_pdf
from models.image_handler import analyze_image
from models.summarizer import summarize_text
from models.translator import translate_text
from models.problem_checker import flag_lab_problems
from PIL import Image
# Initialize Models
models = initialize_models()
# Streamlit App
st.title("Lab Test Analyzer Dashboard")
# File Upload
uploaded_file = st.file_uploader("Upload a Lab Report (PDF, Image, or Text)", type=["pdf", "png", "jpg", "jpeg", "txt"])
if uploaded_file:
file_type = uploaded_file.name.split(".")[-1].lower()
# Extract Text Based on File Type
extracted_text = ""
if file_type == "pdf":
st.write("Processing PDF file...")
extracted_text = parse_pdf(uploaded_file)
elif file_type in ["png", "jpg", "jpeg"]:
st.write("Processing Image file...")
image = Image.open(uploaded_file)
extracted_text = analyze_image(image, models["image_model"])
elif file_type == "txt":
st.write("Processing Text file...")
extracted_text = uploaded_file.read().decode("utf-8")
else:
st.error("Unsupported file type.")
# Display Extracted Text
if extracted_text:
st.subheader("Extracted Content")
st.text_area("Extracted Text", extracted_text, height=200)
# Summarization
summary = summarize_text(extracted_text, models["summarize_model"])
st.subheader("Summary of the Report")
st.text_area("Summary", summary, height=150)
# Sentiment Analysis
st.subheader("Sentiment Analysis")
sentiment, confidence = analyze_sentiment(extracted_text, models["sentiment_model"])
st.write(f"**Sentiment**: {sentiment} (Confidence: {confidence:.2f})")
# Problem Detection
problems = flag_lab_problems(summary)
st.subheader("Detected Problems")
st.write(problems)
# Translation
st.subheader("Translations")
translations = translate_content(summary, models["translation_model"])
st.write("**English**: ", translations["English"])
st.write("**Hindi**: ", translations["Hindi"])
st.write("**Urdu**: ", translations["Urdu"])
else:
st.error("Could not extract text from the uploaded file.")