epochs-demos commited on
Commit
372e060
1 Parent(s): 498def6

Update pages/Brain.py

Browse files
Files changed (1) hide show
  1. pages/Brain.py +49 -29
pages/Brain.py CHANGED
@@ -19,6 +19,8 @@ text_model = BioGptForCausalLM.from_pretrained("microsoft/biogpt")
19
  tokenizer = BioGptTokenizer.from_pretrained("microsoft/biogpt")
20
  labels_path = 'brain_labels.json'
21
  from captum.attr import DeepLift , visualization
 
 
22
 
23
  with open(labels_path) as json_data:
24
  idx_to_labels = json.load(json_data)
@@ -86,7 +88,51 @@ class FineTuneModel(pl.LightningModule):
86
 
87
 
88
 
89
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  st.markdown("<h1 style='text-align: center; '>Brain Tumor Diagnosis</h1>",unsafe_allow_html=True)
92
 
@@ -125,32 +171,6 @@ with st.container():
125
  input_text = f"Patient has {predicted_label} and is advised to take the following medicines:"
126
  with st.spinner('Generating Text'):
127
  generator(input_text, max_length=300, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=1)
128
- st.markdown(generator(input_text, max_length=300, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=1)[0]['generated_text'])
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
  else:
143
- st.success("Please upload an image file 🧠")
144
-
145
-
146
-
147
-
148
-
149
- ## Model Explainibilty Dashboard using Captum
150
-
151
-
152
-
153
-
154
-
155
-
156
-
 
19
  tokenizer = BioGptTokenizer.from_pretrained("microsoft/biogpt")
20
  labels_path = 'brain_labels.json'
21
  from captum.attr import DeepLift , visualization
22
+ import os
23
+ import base64
24
 
25
  with open(labels_path) as json_data:
26
  idx_to_labels = json.load(json_data)
 
88
 
89
 
90
 
91
+ # Get the current working directory
92
+ current_dir = os.getcwd()
93
+
94
+ # Construct the absolute path to the logo.png file
95
+ logo_path = os.path.join(current_dir, "logo.png")
96
+
97
+ with open(logo_path, "rb") as f:
98
+ image_data = f.read()
99
+ image_base64 = base64.b64encode(image_data).decode("utf-8")
100
+
101
+ # Add custom CSS for the header
102
+ header_css = """
103
+ <style>
104
+ .header {
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: center;
108
+ padding: 20px;
109
+ font-size: 18px;
110
+ }
111
+
112
+ .header img {
113
+ margin-right: 10px;
114
+ width: 80px;
115
+ height: 50px;
116
+ }
117
+
118
+ .header p {
119
+ font-size: 14px;
120
+ }
121
+ </style>
122
+ """
123
+
124
+ # Render the custom CSS
125
+ st.markdown(header_css, unsafe_allow_html=True)
126
+
127
+ # Render the header
128
+ header_html = f"""
129
+ <div class="header">
130
+ <img src='data:image/jpeg;base64,{image_base64}' alt="Logo"/>
131
+ <p>Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: contact@1001epochs.co.uk for full solution.</p>
132
+ </div>
133
+ """
134
+
135
+ st.markdown(header_html, unsafe_allow_html=True)
136
 
137
  st.markdown("<h1 style='text-align: center; '>Brain Tumor Diagnosis</h1>",unsafe_allow_html=True)
138
 
 
171
  input_text = f"Patient has {predicted_label} and is advised to take the following medicines:"
172
  with st.spinner('Generating Text'):
173
  generator(input_text, max_length=300, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=1)
174
+ st.markdown(generator(input_text, max_length=300, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=1)[0]['generated_text'])
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  else:
176
+ st.success("Please upload an image file 🧠")