Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,16 +52,18 @@ def analyze_blood_test(file):
|
|
| 52 |
inputs = tokenizer(extracted_text, return_tensors="pt", truncation=True, padding=True)
|
| 53 |
outputs = model(**inputs)
|
| 54 |
|
| 55 |
-
#
|
| 56 |
logits = outputs.logits
|
| 57 |
predictions = logits.softmax(dim=-1)
|
| 58 |
|
| 59 |
# Generate analysis report
|
| 60 |
analysis_report = "🔍 Analysis Results:\n"
|
| 61 |
for i, score in enumerate(predictions[0]):
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
# Step
|
| 65 |
output_pdf = "analysis_report.pdf"
|
| 66 |
create_pdf_report(f"Extracted Text:\n{extracted_text}\n\n{analysis_report}", output_pdf)
|
| 67 |
|
|
|
|
| 52 |
inputs = tokenizer(extracted_text, return_tensors="pt", truncation=True, padding=True)
|
| 53 |
outputs = model(**inputs)
|
| 54 |
|
| 55 |
+
# Step 3: Process logits and generate meaningful labels
|
| 56 |
logits = outputs.logits
|
| 57 |
predictions = logits.softmax(dim=-1)
|
| 58 |
|
| 59 |
# Generate analysis report
|
| 60 |
analysis_report = "🔍 Analysis Results:\n"
|
| 61 |
for i, score in enumerate(predictions[0]):
|
| 62 |
+
token = tokenizer.decode([i]).strip()
|
| 63 |
+
if token not in ["[PAD]", "[unused1]"]: # Filter out invalid tokens
|
| 64 |
+
analysis_report += f"- {token}: {score.item():.2f}\n"
|
| 65 |
|
| 66 |
+
# Step 4: Generate a PDF report
|
| 67 |
output_pdf = "analysis_report.pdf"
|
| 68 |
create_pdf_report(f"Extracted Text:\n{extracted_text}\n\n{analysis_report}", output_pdf)
|
| 69 |
|