Spaces:
Runtime error
Runtime error
Commit
·
b6c14b6
1
Parent(s):
cbc162b
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,80 @@ title = 'MediDiagnostix AI'
|
|
12 |
description = """MediDiagnostix AI allows you to upload medical reports for analysis. Just click a picture of your medical report or upload a pdf report, it will
|
13 |
extract, analyze and provide you the medical interpretations of the report, potential diagnoses, and recommended follow-up actions. Furthermore, you can save diagnosis for future reference"""
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
|
16 |
|
17 |
gr.Markdown(f'<center><h3>{title}</h3></center>')
|
|
|
12 |
description = """MediDiagnostix AI allows you to upload medical reports for analysis. Just click a picture of your medical report or upload a pdf report, it will
|
13 |
extract, analyze and provide you the medical interpretations of the report, potential diagnoses, and recommended follow-up actions. Furthermore, you can save diagnosis for future reference"""
|
14 |
|
15 |
+
import pytesseract # Assuming Tesseract OCR is used for image processing
|
16 |
+
|
17 |
+
def analyze_reports(files, num_reports):
|
18 |
+
"""
|
19 |
+
Process and analyze the uploaded reports.
|
20 |
+
|
21 |
+
Args:
|
22 |
+
files (list): List of uploaded files (PDFs and images).
|
23 |
+
num_reports (int): Number of reports to analyze.
|
24 |
+
|
25 |
+
Returns:
|
26 |
+
str: Analysis results in a formatted text.
|
27 |
+
"""
|
28 |
+
# Check if the number of files matches num_reports
|
29 |
+
if len(files) != num_reports:
|
30 |
+
return "Number of uploaded files does not match the specified number of reports."
|
31 |
+
|
32 |
+
# Initialize a list to hold text from each report
|
33 |
+
report_texts = []
|
34 |
+
|
35 |
+
for file in files:
|
36 |
+
# Check file type and process accordingly
|
37 |
+
if file.name.endswith('.pdf'):
|
38 |
+
# Process PDF file
|
39 |
+
pdf_text = pdf_to_text(file.name)
|
40 |
+
report_texts.extend(pdf_text)
|
41 |
+
else:
|
42 |
+
# Process Image file
|
43 |
+
image_text = image_to_text(file)
|
44 |
+
report_texts.append(image_text)
|
45 |
+
|
46 |
+
# Combine texts from all reports
|
47 |
+
combined_text = ' '.join(report_texts)
|
48 |
+
|
49 |
+
# Analyze the combined text (Placeholder for actual analysis logic)
|
50 |
+
analysis_results = analyze_text(combined_text) # This function needs to be implemented
|
51 |
+
|
52 |
+
return analysis_results
|
53 |
+
|
54 |
+
def image_to_text(image_file):
|
55 |
+
"""
|
56 |
+
Extract text from an image file using OCR.
|
57 |
+
|
58 |
+
Args:
|
59 |
+
image_file (file): An image file.
|
60 |
+
|
61 |
+
Returns:
|
62 |
+
str: Extracted text from the image.
|
63 |
+
"""
|
64 |
+
try:
|
65 |
+
# Read the image file
|
66 |
+
image = Image.open(image_file)
|
67 |
+
# Extract text using OCR
|
68 |
+
extracted_text = pytesseract.image_to_string(image)
|
69 |
+
return extracted_text
|
70 |
+
except Exception as e:
|
71 |
+
return f"Error in text extraction from image: {e}"
|
72 |
+
|
73 |
+
def analyze_text(text):
|
74 |
+
"""
|
75 |
+
Analyze the extracted text and generate insights.
|
76 |
+
|
77 |
+
Args:
|
78 |
+
text (str): Combined text from all reports.
|
79 |
+
|
80 |
+
Returns:
|
81 |
+
str: Analysis results based on the text.
|
82 |
+
"""
|
83 |
+
# Placeholder for text analysis logic
|
84 |
+
# This could involve calling an AI model, processing the text, etc.
|
85 |
+
# Returning a dummy response for demonstration purposes
|
86 |
+
return "Analysis results based on the processed text."
|
87 |
+
|
88 |
+
|
89 |
with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
|
90 |
|
91 |
gr.Markdown(f'<center><h3>{title}</h3></center>')
|