mdasad3617 commited on
Commit
7f334ec
·
verified ·
1 Parent(s): db24518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -27
app.py CHANGED
@@ -1,34 +1,65 @@
 
1
  from models import initialize_models
2
  from models.pdf_handler import parse_pdf
3
  from models.image_handler import analyze_image
4
  from models.summarizer import summarize_text
5
  from models.translator import translate_text
6
  from models.problem_checker import flag_lab_problems
 
7
 
8
- def main():
9
- # Initialize Hugging Face models
10
- models = initialize_models()
11
-
12
- # Example 1: Parse and summarize a PDF lab report
13
- pdf_path = "example_lab_report.pdf"
14
- pdf_text = parse_pdf(pdf_path)
15
- print("Extracted Text from PDF:\n", pdf_text)
16
-
17
- summary = summarize_text(pdf_text, models["summarize_model"])
18
- print("\nSummary:\n", summary)
19
-
20
- # Check for problems in the lab report
21
- problems = flag_lab_problems(summary)
22
- print("\nDetected Problems:\n", problems)
23
-
24
- # Example 2: Translate the summary if needed
25
- translated_summary = translate_text(summary, models["translation_model"])
26
- print("\nTranslated Summary:\n", translated_summary)
27
-
28
- # Example 3: Analyze an image
29
- image_path = "example_lab_image.jpg"
30
- image_results = analyze_image(image_path, models["image_model"])
31
- print("\nImage Analysis Results:\n", image_results)
32
-
33
- if __name__ == "__main__":
34
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  from models import initialize_models
3
  from models.pdf_handler import parse_pdf
4
  from models.image_handler import analyze_image
5
  from models.summarizer import summarize_text
6
  from models.translator import translate_text
7
  from models.problem_checker import flag_lab_problems
8
+ from PIL import Image
9
 
10
+ # Initialize Models
11
+ models = initialize_models()
12
+
13
+ # Streamlit App
14
+ st.title("Lab Test Analyzer Dashboard")
15
+
16
+ # File Upload
17
+ uploaded_file = st.file_uploader("Upload a Lab Report (PDF, Image, or Text)", type=["pdf", "png", "jpg", "jpeg", "txt"])
18
+
19
+ if uploaded_file:
20
+ file_type = uploaded_file.name.split(".")[-1].lower()
21
+
22
+ # Extract Text Based on File Type
23
+ extracted_text = ""
24
+ if file_type == "pdf":
25
+ st.write("Processing PDF file...")
26
+ extracted_text = parse_pdf(uploaded_file)
27
+ elif file_type in ["png", "jpg", "jpeg"]:
28
+ st.write("Processing Image file...")
29
+ image = Image.open(uploaded_file)
30
+ extracted_text = analyze_image(image, models["image_model"])
31
+ elif file_type == "txt":
32
+ st.write("Processing Text file...")
33
+ extracted_text = uploaded_file.read().decode("utf-8")
34
+ else:
35
+ st.error("Unsupported file type.")
36
+
37
+ # Display Extracted Text
38
+ if extracted_text:
39
+ st.subheader("Extracted Content")
40
+ st.text_area("Extracted Text", extracted_text, height=200)
41
+
42
+ # Summarization
43
+ summary = summarize_text(extracted_text, models["summarize_model"])
44
+ st.subheader("Summary of the Report")
45
+ st.text_area("Summary", summary, height=150)
46
+
47
+ # Sentiment Analysis
48
+ st.subheader("Sentiment Analysis")
49
+ sentiment, confidence = analyze_sentiment(extracted_text, models["sentiment_model"])
50
+ st.write(f"**Sentiment**: {sentiment} (Confidence: {confidence:.2f})")
51
+
52
+ # Problem Detection
53
+ problems = flag_lab_problems(summary)
54
+ st.subheader("Detected Problems")
55
+ st.write(problems)
56
+
57
+ # Translation
58
+ st.subheader("Translations")
59
+ translations = translate_content(summary, models["translation_model"])
60
+ st.write("**English**: ", translations["English"])
61
+ st.write("**Hindi**: ", translations["Hindi"])
62
+ st.write("**Urdu**: ", translations["Urdu"])
63
+
64
+ else:
65
+ st.error("Could not extract text from the uploaded file.")