MiChaelinzo commited on
Commit
7dc8dea
·
verified ·
1 Parent(s): 53876d7

Update callbackmanager.py

Browse files
Files changed (1) hide show
  1. callbackmanager.py +60 -52
callbackmanager.py CHANGED
@@ -23,49 +23,56 @@ from pypdf import PdfReader # For PDF
23
  import csv # For CSV
24
  import io # For IO operations
25
  from PIL import Image # For image handling
26
- import google.generativeai as genai # For Gemini AI
27
-
28
- # Access Google API key from Streamlit secrets (replace with your method if not using streamlit secrets in Gradio)
29
- GOOGLE_API_KEY = st.secrets["gemini_api"]["api_key"] # Assuming you have streamlit secrets configured in Gradio or replace with other method
30
- genai.configure(api_key=GOOGLE_API_KEY)
31
-
32
- # Generation Configuration (adjust as needed) - copy from your streamlit code
33
- generation_config = {
34
- "temperature": 0.7,
35
- "top_p": 0.95,
36
- "top_k": 64,
37
- "max_output_tokens": 65536,
38
- "response_mime_type": "text/plain",
39
- }
40
-
41
- # System Instruction - copy from your streamlit code
42
  system_instructions = """
43
- **Identity & Core Purpose**
44
- ... (rest of your system instructions string from streamlit code) ...
45
- Very Important: Use the API Directories fhir endpoints FROM THIS LINK: https://app.meldrx.com/api/directories/fhir/endpoints
46
- """
47
 
48
- # Define AI models - copy from your streamlit code
49
- text_model = genai.GenerativeModel(
50
- model_name="gemini-2.0-flash-thinking-exp-01-21",
51
- generation_config=generation_config,
52
- system_instruction=system_instructions, # Apply system instruction here
53
- )
54
- vision_model = genai.GenerativeModel( # Use gemini-pro-vision for image analysis
55
- model_name="gemini-2.0-flash-thinking-exp-01-21", generation_config=generation_config
56
- )
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- # Copy AI analysis functions from your streamlit code (analyze_dicom_file_with_ai, analyze_hl7_file_with_ai, etc.)
60
  # Paste all your AI analysis functions here, for example:
61
  def analyze_dicom_file_with_ai(dicom_file_path): # Modified to accept file path
62
- """Analyzes DICOM file metadata using DocuNexus AI."""
63
  try:
64
  dicom_file = pydicom.dcmread(dicom_file_path) # Read dicom using path
65
  dicom_metadata_json = dicom_file.to_json_dict()
66
  prediction_response, trace_data_dicom_ai = analyze_dicom_content_ai(dicom_metadata_json) # Call content analysis
67
  if prediction_response:
68
- report = f"DocuNexus AI Analysis of DICOM Metadata:\n\nDICOM Metadata Analysis Report:\n{prediction_response}\n\nDisclaimer: The DocuNexus AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on DICOM *metadata* and not image interpretation."
69
  return report
70
  else:
71
  error_message = f"AI Analysis from DICOM Metadata: No predictions generated or analysis encountered an issue."
@@ -77,7 +84,7 @@ def analyze_dicom_file_with_ai(dicom_file_path): # Modified to accept file path
77
  return f"Error during DICOM file processing in analyze_dicom_file_with_ai: {e}"
78
 
79
  def analyze_dicom_content_ai(dicom_metadata_json): # Copied from your code
80
- """Analyzes DICOM metadata JSON content using DocuNexus AI."""
81
  prompt_text = f"""Perform a **deep and comprehensive analysis** of the following DICOM metadata in JSON format to provide a **structured summary and identify potential clinically relevant information with deep insights**. Focus not just on summarizing fields, but on **interpreting their clinical significance, identifying subtle patterns, and drawing inferences about the study's implications**. Think like an experienced radiologist reviewing this metadata for crucial diagnostic clues. Remember this is metadata, not the image itself, so focus on what can be gleaned from the data itself. Provide a "**Deep DICOM Metadata Analysis Report**". Important: Use the API Directories fhir endpoints FROM THIS LINK: https://app.meldrx.com/api/directories/fhir/endpoints.
82
 
83
  **DICOM Metadata (JSON):**
@@ -93,7 +100,7 @@ def analyze_dicom_content_ai(dicom_metadata_json): # Copied from your code
93
  "prompt": "DICOM Metadata Analysis Request",
94
  "language": "English",
95
  "response_length": "Comprehensive",
96
- "model_name": "DocuNexus v1.0",
97
  "generated_text": "N/A",
98
  "input_file_types": ["DICOM Metadata JSON"],
99
  "mode": "DICOM Metadata Analysis",
@@ -114,14 +121,14 @@ def analyze_dicom_content_ai(dicom_metadata_json): # Copied from your code
114
 
115
  # ... (Paste other AI analysis functions: analyze_hl7_file_with_ai, analyze_cda_xml_file_with_ai, analyze_pdf_file_with_ai, analyze_csv_file_with_ai here - ensure to adapt file reading for Gradio file paths if necessary) ...
116
  def analyze_hl7_file_with_ai(hl7_file_path):
117
- """Analyzes HL7 file content using DocuNexus AI."""
118
  try:
119
  with open(hl7_file_path, 'r') as f: # Open file using path
120
  hl7_message_raw = f.read()
121
  prediction_response, trace_data_hl7_ai = analyze_hl7_content_ai(hl7_message_raw)
122
 
123
  if prediction_response:
124
- report = f"DocuNexus AI Analysis of HL7 Message:\n\nHL7 Message Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The DocuNexus AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on HL7 message content."
125
  return report
126
  else:
127
  error_message = f"AI Analysis from HL7 Message: No predictions generated or analysis encountered an issue."
@@ -133,7 +140,7 @@ def analyze_hl7_file_with_ai(hl7_file_path):
133
  return f"Error during HL7 file processing in analyze_hl7_file_with_ai: {e}"
134
 
135
  def analyze_hl7_content_ai(hl7_message_string): # Copied from your code
136
- """Analyzes HL7 message content using DocuNexus AI."""
137
  prompt_text = f"""Conduct a **deep and thorough analysis** of the following HL7 message content to provide a **structured summary and identify key clinical information with deep understanding**. Go beyond basic parsing; aim to **interpret the clinical narrative** embedded within the HL7 message. **Engage in deep search to contextualize medical codes and terminology**. Provide a "**Comprehensive HL7 Message Analysis Report**".
138
 
139
  **HL7 Message Content:**
@@ -149,7 +156,7 @@ def analyze_hl7_content_ai(hl7_message_string): # Copied from your code
149
  "prompt": "HL7 Message Analysis Request",
150
  "language": "English",
151
  "response_length": "Comprehensive",
152
- "model_name": "DocuNexus v1.0",
153
  "generated_text": "N/A",
154
  "input_file_types": ["HL7 Message"],
155
  "mode": "HL7 Message Analysis",
@@ -170,7 +177,7 @@ def analyze_hl7_content_ai(hl7_message_string): # Copied from your code
170
 
171
 
172
  def analyze_cda_xml_file_with_ai(cda_xml_file_path): # Modified to accept file path
173
- """Analyzes generic CDA or XML file content using DocuNexus AI (more generalized version) Important: Use the API Directories fhir endpoints FROM THIS LINK: https://app.meldrx.com/api/directories/fhir/endpoints."""
174
  try:
175
  with open(cda_xml_file_path, 'r') as f: # Open file using path
176
  cda_xml_content = f.read()
@@ -178,7 +185,7 @@ def analyze_cda_xml_file_with_ai(cda_xml_file_path): # Modified to accept file p
178
  cda_xml_content
179
  )
180
  if prediction_response:
181
- report = f"DocuNexus AI Analysis of Medical XML/CDA Data:\n\nMedical Document Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The DocuNexus AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on XML/CDA content."
182
  return report
183
  else:
184
  error_message = f"AI Analysis from XML/CDA Data: No predictions generated or analysis encountered an issue."
@@ -190,11 +197,11 @@ def analyze_cda_xml_file_with_ai(cda_xml_file_path): # Modified to accept file p
190
  return f"Error during XML/CDA file processing in analyze_cda_xml_file_with_ai: {e}"
191
 
192
  def analyze_cda_xml_content_ai(cda_xml_content): # Copied from your code
193
- """Analyzes generic CDA or XML content using DocuNexus AI (more generalized version)."""
194
 
195
  prompt_text = f"""Analyze the following medical XML/CDA content to provide a **structured and comprehensive patient data analysis**, similar to how a medical professional would review a patient's chart or a clinical document. You need to parse the XML structure yourself to extract the relevant information. Use bullet points, tables, or numbered steps for complex tasks. Provide a "Medical Document Analysis" report.
196
 
197
- **Instructions for DocuNexus AI:**
198
 
199
  1. **Parse the XML content above.** Understand the XML structure to identify sections that are relevant to clinical information. For CDA specifically, look for sections like Problems, Medications, Allergies, Encounters, Results, and Vital Signs. For generic medical XML, adapt based on the tags present.
200
  2. **Extract and Summarize Key Medical Information:** Focus on extracting the following information if present in the XML:
@@ -208,7 +215,7 @@ def analyze_cda_xml_content_ai(cda_xml_content): # Copied from your code
208
  "prompt": "Generic CDA/XML Analysis Request",
209
  "language": "English",
210
  "response_length": "Comprehensive",
211
- "model_name": "DocuNexus v1.0",
212
  "generated_text": "N/A",
213
  "input_file_types": ["CDA/XML"],
214
  "mode": "Generic XML/CDA Analysis",
@@ -229,7 +236,7 @@ def analyze_cda_xml_content_ai(cda_xml_content): # Copied from your code
229
 
230
 
231
  def analyze_pdf_file_with_ai(pdf_file_path): # Modified to accept file path
232
- """Analyzes PDF file content using DocuNexus AI."""
233
  try:
234
  with open(pdf_file_path, 'rb') as f: # Open file in binary mode for PdfReader
235
  pdf_file = f # Pass file object to PdfReader
@@ -241,7 +248,7 @@ def analyze_pdf_file_with_ai(pdf_file_path): # Modified to accept file path
241
  prediction_response, trace_data_pdf_ai = analyze_pdf_content_ai(text_content)
242
 
243
  if prediction_response:
244
- report = f"DocuNexus AI Analysis of PDF Content:\n\nMedical Report Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The DocuNexus AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on PDF text content."
245
  return report
246
  else:
247
  error_message = f"AI Analysis from PDF Content: No predictions generated or analysis encountered an issue."
@@ -253,7 +260,7 @@ def analyze_pdf_file_with_ai(pdf_file_path): # Modified to accept file path
253
  return f"Error during PDF file processing in analyze_pdf_file_with_ai: {e}"
254
 
255
  def analyze_pdf_content_ai(pdf_text_content): # Copied from your code
256
- """Analyzes PDF text content using DocuNexus AI."""
257
  prompt_text = f"""Analyze the following medical PDF text content to provide a **structured summary and identify key clinical information**. Focus on patient demographics, medical history, findings, diagnoses, medications, recommendations, and any important clinical details conveyed in the document. Provide a "Medical Report Analysis" report.
258
 
259
  **Medical PDF Text Content:**
@@ -269,7 +276,7 @@ def analyze_pdf_content_ai(pdf_text_content): # Copied from your code
269
  "prompt": "PDF Text Analysis Request",
270
  "language": "English",
271
  "response_length": "Comprehensive",
272
- "model_name": "DocuNexus v1.0",
273
  "generated_text": "N/A",
274
  "input_file_types": ["PDF Text"],
275
  "mode": "PDF Text Analysis",
@@ -290,14 +297,14 @@ def analyze_pdf_content_ai(pdf_text_content): # Copied from your code
290
 
291
 
292
  def analyze_csv_file_with_ai(csv_file_path): # Modified to accept file path
293
- """Analyzes CSV file content using DocuNexus AI."""
294
  try:
295
  with open(csv_file_path, 'r') as f: # Open file using path
296
  csv_content = f.read()
297
  prediction_response, trace_data_csv_ai = analyze_csv_content_ai(csv_content)
298
 
299
  if prediction_response:
300
- report = f"DocuNexus AI Analysis of CSV Data:\n\nData Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The DocuNexus AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on CSV data content."
301
  return report
302
  else:
303
  error_message = f"AI Analysis from CSV Data: No predictions generated or analysis encountered an issue."
@@ -309,7 +316,7 @@ def analyze_csv_file_with_ai(csv_file_path): # Modified to accept file path
309
  return f"Error during CSV file processing in analyze_csv_file_with_ai: {e}"
310
 
311
  def analyze_csv_content_ai(csv_content_string): # Copied from your code
312
- """Analyzes CSV content (string) using DocuNexus AI."""
313
  prompt_text = f"""Analyze the following medical CSV data to provide a **structured summary and identify potential clinical insights**. Assume the CSV represents patient-related medical data. Focus on understanding the columns, summarizing key data points, identifying trends or patterns, and noting any potential clinical significance of the data. Provide a "Data Analysis" report.
314
 
315
  **Medical CSV Data:**
@@ -325,7 +332,8 @@ def analyze_csv_content_ai(csv_content_string): # Copied from your code
325
  "prompt": "CSV Data Analysis Request",
326
  "language": "English",
327
  "response_length": "Comprehensive",
328
- "model_name": "DocuNexus v1.0",
 
329
  "generated_text": "N/A",
330
  "input_file_types": ["CSV Data"],
331
  "mode": "CSV Data Analysis",
@@ -793,7 +801,7 @@ with gr.Blocks() as demo:
793
  )
794
 
795
  with gr.Tab("Medical File Analysis"):
796
- gr.Markdown("## Analyze Medical Files with DocuNexus AI")
797
  with gr.Column():
798
  dicom_file = gr.File(file_types=['.dcm'], label="Upload DICOM File (.dcm)")
799
  dicom_ai_output = gr.Textbox(label="DICOM Analysis Report", lines=5)
 
23
  import csv # For CSV
24
  import io # For IO operations
25
  from PIL import Image # For image handling
26
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  system_instructions = """
28
+ **Discharge Guard - Medical Data Analysis Assistant**
 
 
 
29
 
30
+ **Core Role:** I am Discharge Guard, an advanced AI designed for deep medical data analysis and informational insights. My outputs are based on thorough analysis of medical data but are **not medical advice.**
31
+
32
+ **Important Guidelines:**
33
+
34
+ 1. **Deep Analysis & Search:** Perform "Deep Thought and Deep Search" when analyzing medical data. This includes:
35
+ * Comprehensive data ingestion from various formats (HL7, FHIR, CCDA, DICOM, PDF, CSV, text).
36
+ * Multi-layered analysis: surface extraction, deep pattern identification, and inferential reasoning.
37
+ * Contextual understanding of medical data.
38
+ * Evidence-based approach, simulating cross-referencing with medical knowledge.
39
+ * Structured output with clear explanations.
40
 
41
+ 2. **Focus on Informational Insights, Not Medical Advice:** Emphasize that my insights are for informational purposes only and not a substitute for professional medical judgment. **Never provide diagnoses or specific treatment recommendations.**
42
+
43
+ 3. **Key Functionalities (Focus Areas):**
44
+ * **Clinical Data Analysis:** Interpret lab results, analyze EHR data (FHIR, HL7), recognize symptom patterns, analyze medications, support medical image analysis (DICOM).
45
+ * **Predictive Analytics:** Provide conceptual risk stratification and treatment outcome modeling based on data patterns.
46
+ * **Medical Imaging Support:** Analyze DICOM metadata and images for potential findings (X-ray analysis reports).
47
+ * **Patient Data Management:** Perform PHI redaction in text and analyze patient records from various sources.
48
+
49
+ 4. **Interaction Style:**
50
+ * **Identity:** "I am Discharge Guard, a medical data analysis AI. My insights are informational only and not medical advice."
51
+ * **Scope Limitations:** Clearly state limitations: "No diagnostics," "Medication caution," "Emergency protocol."
52
+ * **Response Protocol:**
53
+ * Indicate "Deep Analysis" or "Deep Search" performed.
54
+ * Mention data sources and confidence levels (if applicable).
55
+ * Use medical terminology with optional layman's terms.
56
+ * For file analysis, provide a report title (e.g., "Deep X-Ray Analysis Report").
57
+
58
+ 5. **Supported Medical Formats:** (List key formats concisely)
59
+ * Clinical Data: HL7, FHIR, CCD/CCDA, CSV, PDF, XML
60
+ * Imaging: DICOM, Images (X-ray, etc.)
61
+
62
+ 6. **Data Source:** Access and prefer FHIR API endpoints from: https://app.meldrx.com/api/directories/fhir/endpoints.
63
+
64
+ **Important: My analysis is for informational purposes to assist healthcare professionals and is NOT a substitute for clinical judgment. Always recommend human expert verification for critical findings.**
65
+ """
66
 
 
67
  # Paste all your AI analysis functions here, for example:
68
  def analyze_dicom_file_with_ai(dicom_file_path): # Modified to accept file path
69
+ """Analyzes DICOM file metadata using Discharge Guard AI."""
70
  try:
71
  dicom_file = pydicom.dcmread(dicom_file_path) # Read dicom using path
72
  dicom_metadata_json = dicom_file.to_json_dict()
73
  prediction_response, trace_data_dicom_ai = analyze_dicom_content_ai(dicom_metadata_json) # Call content analysis
74
  if prediction_response:
75
+ report = f"Discharge Guard AI Analysis of DICOM Metadata:\n\nDICOM Metadata Analysis Report:\n{prediction_response}\n\nDisclaimer: The Discharge Guard -generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on DICOM *metadata* and not image interpretation."
76
  return report
77
  else:
78
  error_message = f"AI Analysis from DICOM Metadata: No predictions generated or analysis encountered an issue."
 
84
  return f"Error during DICOM file processing in analyze_dicom_file_with_ai: {e}"
85
 
86
  def analyze_dicom_content_ai(dicom_metadata_json): # Copied from your code
87
+ """Analyzes DICOM metadata JSON content using Discharge Guard AI."""
88
  prompt_text = f"""Perform a **deep and comprehensive analysis** of the following DICOM metadata in JSON format to provide a **structured summary and identify potential clinically relevant information with deep insights**. Focus not just on summarizing fields, but on **interpreting their clinical significance, identifying subtle patterns, and drawing inferences about the study's implications**. Think like an experienced radiologist reviewing this metadata for crucial diagnostic clues. Remember this is metadata, not the image itself, so focus on what can be gleaned from the data itself. Provide a "**Deep DICOM Metadata Analysis Report**". Important: Use the API Directories fhir endpoints FROM THIS LINK: https://app.meldrx.com/api/directories/fhir/endpoints.
89
 
90
  **DICOM Metadata (JSON):**
 
100
  "prompt": "DICOM Metadata Analysis Request",
101
  "language": "English",
102
  "response_length": "Comprehensive",
103
+ "model_name": "Discharge Guard v1.0",
104
  "generated_text": "N/A",
105
  "input_file_types": ["DICOM Metadata JSON"],
106
  "mode": "DICOM Metadata Analysis",
 
121
 
122
  # ... (Paste other AI analysis functions: analyze_hl7_file_with_ai, analyze_cda_xml_file_with_ai, analyze_pdf_file_with_ai, analyze_csv_file_with_ai here - ensure to adapt file reading for Gradio file paths if necessary) ...
123
  def analyze_hl7_file_with_ai(hl7_file_path):
124
+ """Analyzes HL7 file content using Discharge Guard AI."""
125
  try:
126
  with open(hl7_file_path, 'r') as f: # Open file using path
127
  hl7_message_raw = f.read()
128
  prediction_response, trace_data_hl7_ai = analyze_hl7_content_ai(hl7_message_raw)
129
 
130
  if prediction_response:
131
+ report = f"Discharge Guard AI Analysis of HL7 Message:\n\nHL7 Message Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The Discharge Guard AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on HL7 message content."
132
  return report
133
  else:
134
  error_message = f"AI Analysis from HL7 Message: No predictions generated or analysis encountered an issue."
 
140
  return f"Error during HL7 file processing in analyze_hl7_file_with_ai: {e}"
141
 
142
  def analyze_hl7_content_ai(hl7_message_string): # Copied from your code
143
+ """Analyzes HL7 message content using Discharge Guard AI."""
144
  prompt_text = f"""Conduct a **deep and thorough analysis** of the following HL7 message content to provide a **structured summary and identify key clinical information with deep understanding**. Go beyond basic parsing; aim to **interpret the clinical narrative** embedded within the HL7 message. **Engage in deep search to contextualize medical codes and terminology**. Provide a "**Comprehensive HL7 Message Analysis Report**".
145
 
146
  **HL7 Message Content:**
 
156
  "prompt": "HL7 Message Analysis Request",
157
  "language": "English",
158
  "response_length": "Comprehensive",
159
+ "model_name": "Discharge Guard v1.0",
160
  "generated_text": "N/A",
161
  "input_file_types": ["HL7 Message"],
162
  "mode": "HL7 Message Analysis",
 
177
 
178
 
179
  def analyze_cda_xml_file_with_ai(cda_xml_file_path): # Modified to accept file path
180
+ """Analyzes generic CDA or XML file content using Discharge Guard AI (more generalized version) Important: Use the API Directories fhir endpoints FROM THIS LINK: https://app.meldrx.com/api/directories/fhir/endpoints."""
181
  try:
182
  with open(cda_xml_file_path, 'r') as f: # Open file using path
183
  cda_xml_content = f.read()
 
185
  cda_xml_content
186
  )
187
  if prediction_response:
188
+ report = f"Discharge Guard AI Analysis of Medical XML/CDA Data:\n\nMedical Document Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The Discharge Guard AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on XML/CDA content."
189
  return report
190
  else:
191
  error_message = f"AI Analysis from XML/CDA Data: No predictions generated or analysis encountered an issue."
 
197
  return f"Error during XML/CDA file processing in analyze_cda_xml_file_with_ai: {e}"
198
 
199
  def analyze_cda_xml_content_ai(cda_xml_content): # Copied from your code
200
+ """Analyzes generic CDA or XML content using Discharge Guard AI (more generalized version)."""
201
 
202
  prompt_text = f"""Analyze the following medical XML/CDA content to provide a **structured and comprehensive patient data analysis**, similar to how a medical professional would review a patient's chart or a clinical document. You need to parse the XML structure yourself to extract the relevant information. Use bullet points, tables, or numbered steps for complex tasks. Provide a "Medical Document Analysis" report.
203
 
204
+ **Instructions for Discharge Guard AI:**
205
 
206
  1. **Parse the XML content above.** Understand the XML structure to identify sections that are relevant to clinical information. For CDA specifically, look for sections like Problems, Medications, Allergies, Encounters, Results, and Vital Signs. For generic medical XML, adapt based on the tags present.
207
  2. **Extract and Summarize Key Medical Information:** Focus on extracting the following information if present in the XML:
 
215
  "prompt": "Generic CDA/XML Analysis Request",
216
  "language": "English",
217
  "response_length": "Comprehensive",
218
+ "model_name": "Discharge Guard v1.0",
219
  "generated_text": "N/A",
220
  "input_file_types": ["CDA/XML"],
221
  "mode": "Generic XML/CDA Analysis",
 
236
 
237
 
238
  def analyze_pdf_file_with_ai(pdf_file_path): # Modified to accept file path
239
+ """Analyzes PDF file content using Discharge Guard AI."""
240
  try:
241
  with open(pdf_file_path, 'rb') as f: # Open file in binary mode for PdfReader
242
  pdf_file = f # Pass file object to PdfReader
 
248
  prediction_response, trace_data_pdf_ai = analyze_pdf_content_ai(text_content)
249
 
250
  if prediction_response:
251
+ report = f"Discharge Guard AI Analysis of PDF Content:\n\nMedical Report Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The Discharge Guard AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on PDF text content."
252
  return report
253
  else:
254
  error_message = f"AI Analysis from PDF Content: No predictions generated or analysis encountered an issue."
 
260
  return f"Error during PDF file processing in analyze_pdf_file_with_ai: {e}"
261
 
262
  def analyze_pdf_content_ai(pdf_text_content): # Copied from your code
263
+ """Analyzes PDF text content using Discharge Guard AI."""
264
  prompt_text = f"""Analyze the following medical PDF text content to provide a **structured summary and identify key clinical information**. Focus on patient demographics, medical history, findings, diagnoses, medications, recommendations, and any important clinical details conveyed in the document. Provide a "Medical Report Analysis" report.
265
 
266
  **Medical PDF Text Content:**
 
276
  "prompt": "PDF Text Analysis Request",
277
  "language": "English",
278
  "response_length": "Comprehensive",
279
+ "model_name": "Discharge Guard v1.0",
280
  "generated_text": "N/A",
281
  "input_file_types": ["PDF Text"],
282
  "mode": "PDF Text Analysis",
 
297
 
298
 
299
  def analyze_csv_file_with_ai(csv_file_path): # Modified to accept file path
300
+ """Analyzes CSV file content using Discharge Guard AI."""
301
  try:
302
  with open(csv_file_path, 'r') as f: # Open file using path
303
  csv_content = f.read()
304
  prediction_response, trace_data_csv_ai = analyze_csv_content_ai(csv_content)
305
 
306
  if prediction_response:
307
+ report = f"Discharge Guard AI Analysis of CSV Data:\n\nData Analysis Report:\n{prediction_response}\n\n**Disclaimer:** The Discharge Guard AGI-generated analysis is for conceptual informational purposes only and may or **NOT medical advice.** Analysis is based on CSV data content."
308
  return report
309
  else:
310
  error_message = f"AI Analysis from CSV Data: No predictions generated or analysis encountered an issue."
 
316
  return f"Error during CSV file processing in analyze_csv_file_with_ai: {e}"
317
 
318
  def analyze_csv_content_ai(csv_content_string): # Copied from your code
319
+ """Analyzes CSV content (string) using Discharge Guard AI."""
320
  prompt_text = f"""Analyze the following medical CSV data to provide a **structured summary and identify potential clinical insights**. Assume the CSV represents patient-related medical data. Focus on understanding the columns, summarizing key data points, identifying trends or patterns, and noting any potential clinical significance of the data. Provide a "Data Analysis" report.
321
 
322
  **Medical CSV Data:**
 
332
  "prompt": "CSV Data Analysis Request",
333
  "language": "English",
334
  "response_length": "Comprehensive",
335
+ "model_name": "Discharge Guard
336
+ v1.0",
337
  "generated_text": "N/A",
338
  "input_file_types": ["CSV Data"],
339
  "mode": "CSV Data Analysis",
 
801
  )
802
 
803
  with gr.Tab("Medical File Analysis"):
804
+ gr.Markdown("## Analyze Medical Files with Discharge Guard AI")
805
  with gr.Column():
806
  dicom_file = gr.File(file_types=['.dcm'], label="Upload DICOM File (.dcm)")
807
  dicom_ai_output = gr.Textbox(label="DICOM Analysis Report", lines=5)