ashishkgpian commited on
Commit
a0b81f5
·
verified ·
1 Parent(s): 1948f3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -85
app.py CHANGED
@@ -8,116 +8,87 @@ classifier = pipeline(
8
  )
9
 
10
  def classify_symptoms(text):
11
- """
12
- Classify medical symptoms and return top ICD9 codes
13
-
14
- Args:
15
- text (str): Input medical symptom description
16
-
17
- Returns:
18
- dict: Top classification results with ICD9 codes and probabilities
19
- """
20
  try:
21
- # Get classification results
22
  results = classifier(text, top_k=5)
23
-
24
- # Format results for more readable output
25
  formatted_results = []
26
  for result in results:
27
  formatted_results.append({
28
  "ICD9 Code": result['label'],
29
  "Confidence": f"{result['score']:.2%}"
30
  })
31
-
32
  return formatted_results
33
-
34
  except Exception as e:
35
  return f"Error processing classification: {str(e)}"
36
 
37
- # Custom CSS for medical-themed UI
38
  custom_css = """
39
- /* Medical-inspired color palette and design */
40
  .gradio-container {
41
- background-color: #f4f7f6;
42
- font-family: 'Arial', 'Helvetica Neue', sans-serif;
43
  }
44
 
45
- /* Styled input area */
46
- .input-container {
47
- background-color: #ffffff;
48
- border: 2px solid #3498db;
49
- border-radius: 10px;
50
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
51
- padding: 15px;
52
  }
53
 
54
- /* Result card styling */
55
- .result-card {
56
- background-color: #ffffff;
57
- border-left: 5px solid #2ecc71;
58
- margin-bottom: 10px;
59
- padding: 10px;
60
- border-radius: 5px;
61
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
62
  }
63
 
64
- /* Medical icon-like styling for headers */
65
- .gradio-header {
66
- color: #2c3e50;
67
- text-align: center;
68
- font-weight: bold;
69
  }
70
 
71
- /* Soften the medical green theme */
72
- .submit-button {
73
- background-color: #2ecc71 !important;
74
- color: white !important;
75
- border: none !important;
76
- transition: all 0.3s ease;
77
- }
78
-
79
- .submit-button:hover {
80
- background-color: #27ae60 !important;
81
- transform: scale(1.05);
82
  }
83
  """
84
 
85
- # Create Gradio interface with advanced medical-themed design
86
- demo = gr.Interface(
87
- fn=classify_symptoms,
88
- inputs=gr.Textbox(
89
- label="Patient Symptom Description",
90
- placeholder="Enter detailed patient symptoms (e.g., 'Patient reports persistent chest pain radiating to left arm, accompanied by shortness of breath')",
91
- lines=4,
92
- container=False,
93
- elem_classes=["input-container"]
94
- ),
95
- outputs=gr.JSON(
96
- label="Diagnostic Suggestions",
97
- elem_classes=["result-card"]
98
- ),
99
- title="Symptom-to-ICD9 Classifier",
100
- description="An advanced AI-powered diagnostic assistance tool for converting clinical symptom descriptions into potential ICD9 diagnostic codes.",
101
- theme="huggingface",
102
- css=custom_css,
103
- examples=[
104
- ["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
105
- ["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
106
- ["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
107
- ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
108
- ]
109
- )
110
-
111
- # Add some footer-like information
112
- demo.layout = gr.Column(
113
- [
114
- demo.title,
115
- demo.description,
116
- demo.input,
117
- demo.output,
118
- gr.Markdown("**Disclaimer:** This is an AI-assisted diagnostic tool. Always consult with a healthcare professional for accurate diagnosis and treatment.")
119
- ]
120
- )
121
 
122
  if __name__ == "__main__":
123
  demo.launch()
 
8
  )
9
 
10
  def classify_symptoms(text):
 
 
 
 
 
 
 
 
 
11
  try:
 
12
  results = classifier(text, top_k=5)
 
 
13
  formatted_results = []
14
  for result in results:
15
  formatted_results.append({
16
  "ICD9 Code": result['label'],
17
  "Confidence": f"{result['score']:.2%}"
18
  })
 
19
  return formatted_results
 
20
  except Exception as e:
21
  return f"Error processing classification: {str(e)}"
22
 
23
+ # Custom CSS without theme dependencies
24
  custom_css = """
 
25
  .gradio-container {
26
+ background-color: #f8f9fa;
 
27
  }
28
 
29
+ .contain {
30
+ background-color: white !important;
31
+ border-radius: 8px !important;
32
+ padding: 20px !important;
33
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
34
+ margin-bottom: 20px !important;
 
35
  }
36
 
37
+ .textbox {
38
+ border: 2px solid #4a90e2 !important;
39
+ border-radius: 6px !important;
 
 
 
 
 
40
  }
41
 
42
+ .label {
43
+ color: #2c3e50 !important;
44
+ font-weight: bold !important;
45
+ font-size: 1.1em !important;
 
46
  }
47
 
48
+ footer {
49
+ text-align: center;
50
+ padding: 20px;
51
+ color: #666;
52
+ font-size: 0.9em;
 
 
 
 
 
 
53
  }
54
  """
55
 
56
+ with gr.Blocks(css=custom_css) as demo:
57
+ gr.Markdown(
58
+ """
59
+ # MedAI: Clinical Symptom ICD9 Classifier
60
+ ### AI-Powered Diagnostic Code Suggestion Tool
61
+ """
62
+ )
63
+
64
+ with gr.Row():
65
+ with gr.Column():
66
+ input_text = gr.Textbox(
67
+ label="Patient Symptom Description",
68
+ placeholder="Enter detailed patient symptoms (e.g., 'Patient reports persistent chest pain radiating to left arm, accompanied by shortness of breath')",
69
+ lines=4
70
+ )
71
+
72
+ examples = gr.Examples(
73
+ examples=[
74
+ ["45-year-old male experiencing severe chest pain, radiating to left arm, with shortness of breath and excessive sweating"],
75
+ ["Persistent headache for 2 weeks, accompanied by dizziness and occasional blurred vision"],
76
+ ["Diabetic patient reporting frequent urination, increased thirst, and unexplained weight loss"],
77
+ ["Elderly patient with chronic knee pain, reduced mobility, and signs of inflammation"]
78
+ ],
79
+ inputs=input_text
80
+ )
81
+
82
+ output = gr.JSON(label="Diagnostic Suggestions")
83
+
84
+ input_text.submit(fn=classify_symptoms, inputs=input_text, outputs=output)
85
+
86
+ gr.Markdown(
87
+ """
88
+ ---
89
+ **Disclaimer:** This is an AI-assisted diagnostic tool. Always consult with a healthcare professional for accurate diagnosis and treatment.
90
+ """
91
+ )
92
 
93
  if __name__ == "__main__":
94
  demo.launch()