Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,29 @@
|
|
1 |
-
import requests
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
5 |
import torch.nn.functional as F
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Load tokenizer and model
|
12 |
tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
13 |
model = AutoModelForSequenceClassification.from_pretrained("emilyalsentzer/Bio_ClinicalBERT", num_labels=1000) # Adjust num_labels as needed
|
14 |
|
15 |
-
# Function to fetch ICD codes from API
|
16 |
-
def fetch_icd_codes(query):
|
17 |
-
try:
|
18 |
-
response = requests.get(f"{ICD_API_URL}?desc={query}")
|
19 |
-
if response.status_code == 200:
|
20 |
-
return response.json() # Adjust based on API response format
|
21 |
-
else:
|
22 |
-
return []
|
23 |
-
except Exception as e:
|
24 |
-
print(f"Error fetching ICD codes: {e}")
|
25 |
-
return []
|
26 |
-
|
27 |
-
# Function to fetch CPT codes from API
|
28 |
-
def fetch_cpt_codes(query):
|
29 |
-
try:
|
30 |
-
response = requests.get(f"{CPT_API_URL}?desc={query}")
|
31 |
-
if response.status_code == 200:
|
32 |
-
return response.json() # Adjust based on API response format
|
33 |
-
else:
|
34 |
-
return []
|
35 |
-
except Exception as e:
|
36 |
-
print(f"Error fetching CPT codes: {e}")
|
37 |
-
return []
|
38 |
-
|
39 |
# Prediction function
|
40 |
def predict_codes(text):
|
41 |
if not text.strip():
|
@@ -62,7 +50,7 @@ def predict_codes(text):
|
|
62 |
# Get top 3 predictions
|
63 |
top_k = torch.topk(probs, k=3)
|
64 |
|
65 |
-
# Fetch ICD and CPT codes using
|
66 |
icd_results = fetch_icd_codes(text)
|
67 |
cpt_results = fetch_cpt_codes(text)
|
68 |
|
@@ -80,8 +68,15 @@ def predict_codes(text):
|
|
80 |
# Create Gradio interface
|
81 |
iface = gr.Interface(
|
82 |
fn=predict_codes,
|
83 |
-
inputs=gr.Textbox(
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
title="AutoRCM - Medical Code Predictor",
|
86 |
description="Enter a medical summary to get recommended ICD-10 and CPT codes.",
|
87 |
examples=[
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
import torch.nn.functional as F
|
5 |
|
6 |
+
# Mock ICD and CPT data (replace with actual API calls or datasets)
|
7 |
+
def fetch_icd_codes(query):
|
8 |
+
# Mock ICD codes for demonstration
|
9 |
+
return [
|
10 |
+
{"code": "R50.9", "description": "Fever, unspecified"},
|
11 |
+
{"code": "A00", "description": "Cholera"},
|
12 |
+
{"code": "J06.9", "description": "Acute upper respiratory infection, unspecified"}
|
13 |
+
]
|
14 |
+
|
15 |
+
def fetch_cpt_codes(query):
|
16 |
+
# Mock CPT codes for demonstration
|
17 |
+
return [
|
18 |
+
{"code": "99213", "description": "Office or other outpatient visit"},
|
19 |
+
{"code": "87804", "description": "Infectious agent detection by immunoassay"},
|
20 |
+
{"code": "85025", "description": "Complete blood count (CBC)"}
|
21 |
+
]
|
22 |
|
23 |
# Load tokenizer and model
|
24 |
tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
25 |
model = AutoModelForSequenceClassification.from_pretrained("emilyalsentzer/Bio_ClinicalBERT", num_labels=1000) # Adjust num_labels as needed
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Prediction function
|
28 |
def predict_codes(text):
|
29 |
if not text.strip():
|
|
|
50 |
# Get top 3 predictions
|
51 |
top_k = torch.topk(probs, k=3)
|
52 |
|
53 |
+
# Fetch ICD and CPT codes using mock functions
|
54 |
icd_results = fetch_icd_codes(text)
|
55 |
cpt_results = fetch_cpt_codes(text)
|
56 |
|
|
|
68 |
# Create Gradio interface
|
69 |
iface = gr.Interface(
|
70 |
fn=predict_codes,
|
71 |
+
inputs=gr.Textbox(
|
72 |
+
lines=5,
|
73 |
+
placeholder="Enter medical summary here...",
|
74 |
+
label="Medical Summary"
|
75 |
+
),
|
76 |
+
outputs=gr.Textbox(
|
77 |
+
label="Predicted Codes",
|
78 |
+
lines=10
|
79 |
+
),
|
80 |
title="AutoRCM - Medical Code Predictor",
|
81 |
description="Enter a medical summary to get recommended ICD-10 and CPT codes.",
|
82 |
examples=[
|