Spaces:
Runtime error
Runtime error
Commit
·
f2afde8
1
Parent(s):
2afb296
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ from docx import Document
|
|
11 |
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
12 |
from io import BytesIO
|
13 |
|
14 |
-
# Set up OpenAI API
|
15 |
openai.api_key = "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"
|
16 |
|
17 |
st.markdown(
|
@@ -44,21 +43,6 @@ st.markdown(
|
|
44 |
padding: 10px; /* Add padding to the headers */
|
45 |
border-radius: 5px; /* Add border-radius to the headers */
|
46 |
}
|
47 |
-
.feedback_button {
|
48 |
-
display: inline-block;
|
49 |
-
background-color: #e0e0e0;
|
50 |
-
padding: 10px;
|
51 |
-
margin: 5px;
|
52 |
-
border-radius: 10px;
|
53 |
-
box-shadow: 3px 3px 5px #bfbfbf, -3px -3px 5px #ffffff;
|
54 |
-
transition: box-shadow 0.3s ease;
|
55 |
-
}
|
56 |
-
.feedback_button:hover {
|
57 |
-
box-shadow: inset 3px 3px 5px #bfbfbf, inset -3px -3px 5px #ffffff;
|
58 |
-
}
|
59 |
-
.feedback_button:active {
|
60 |
-
box-shadow: inset 5px 5px 7px #bfbfbf, inset -5px -5px 7px #ffffff;
|
61 |
-
}
|
62 |
</style>
|
63 |
""",
|
64 |
unsafe_allow_html=True,
|
@@ -71,23 +55,6 @@ model = CLIPModel().to(device)
|
|
71 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
72 |
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
73 |
|
74 |
-
def send_report_text(ctx, text):
|
75 |
-
server = Server.get_current()
|
76 |
-
if server:
|
77 |
-
for session in server._session_infos.values():
|
78 |
-
this_session = session.session
|
79 |
-
if this_session == ctx:
|
80 |
-
this_session.send_message({"type": "reportText", "text": text})
|
81 |
-
|
82 |
-
def on_message(message, ctx):
|
83 |
-
if "type" in message and message["type"] == "getReport":
|
84 |
-
report_text = radiology_report_with_personal_info # Replace this with the actual report text
|
85 |
-
send_report_text(ctx, report_text)
|
86 |
-
|
87 |
-
def main():
|
88 |
-
ctx = st.session_state._get_report_ctx()
|
89 |
-
add_report_ctx(ctx, on_message)
|
90 |
-
|
91 |
def download_link(content, filename, link_text):
|
92 |
b64 = base64.b64encode(content).decode()
|
93 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
@@ -147,65 +114,15 @@ if uploaded_file is not None:
|
|
147 |
# Add personal information to the radiology report
|
148 |
radiology_report_with_personal_info = f"Patient Name: {first_name} {last_name}\nAge: {age}\nGender: {gender}\n\n{radiology_report}"
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
#
|
162 |
-
better_icon = "data:image/png;base64,iVBORw0KGg..."
|
163 |
-
satisfied_icon = "data:image/png;base64,iVBORw0KGg..."
|
164 |
-
worse_icon = "data:image/png;base64,iVBORw0KGg..."
|
165 |
-
|
166 |
-
# Custom feedback buttons with neumorphic design and icons
|
167 |
-
feedback_html = f"""
|
168 |
-
<div style="display: flex; justify-content: center;">
|
169 |
-
<div class="feedback_button" id="better_button" style="cursor:pointer;">
|
170 |
-
<img src="{better_icon}" width="30" height="30" alt="Better Icon">
|
171 |
-
<p>Better</p>
|
172 |
-
</div>
|
173 |
-
<div class="feedback_button" id="satisfied_button" style="cursor:pointer;">
|
174 |
-
<img src="{satisfied_icon}" width="30" height="30" alt="Satisfied Icon">
|
175 |
-
<p>Satisfied</p>
|
176 |
-
</div>
|
177 |
-
<div class="feedback_button" id="worse_button" style="cursor:pointer;">
|
178 |
-
<img src="{worse_icon}" width="30" height="30" alt="Worse Icon">
|
179 |
-
<p>Regenerate Report...?</p>
|
180 |
-
</div>
|
181 |
-
</div>
|
182 |
-
"""
|
183 |
-
|
184 |
-
st.markdown(feedback_html, unsafe_allow_html=True)
|
185 |
-
|
186 |
-
# Define a function to handle feedback button clicks
|
187 |
-
def handle_feedback_button_click(feedback):
|
188 |
-
if feedback == 'Regenerate Report...?':
|
189 |
-
# Regenerate and display the radiology report
|
190 |
-
radiology_report = generate_radiology_report(f"Write Complete Radiology Report for this: {caption}")
|
191 |
-
radiology_report_with_personal_info = f"Patient Name: {first_name} {last_name}\nAge: {age}\nGender: {gender}\n\n{radiology_report}"
|
192 |
-
container = st.container()
|
193 |
-
with container:
|
194 |
-
st.header("Radiology Report")
|
195 |
-
st.write(radiology_report_with_personal_info)
|
196 |
-
st.markdown(download_link(save_as_docx(radiology_report_with_personal_info, "radiology_report.docx"), "radiology_report.docx", "Download Report as DOCX"), unsafe_allow_html=True)
|
197 |
-
# Implement other feedback handling logic here
|
198 |
-
|
199 |
-
# Capture feedback button clicks
|
200 |
-
with st.empty():
|
201 |
-
feedback_button_click = st.button("Better", key="better_button")
|
202 |
-
if feedback_button_click:
|
203 |
-
handle_feedback_button_click('better')
|
204 |
-
|
205 |
-
feedback_button_click = st.button("Satisfied", key="satisfied_button")
|
206 |
-
if feedback_button_click:
|
207 |
-
handle_feedback_button_click('satisfied')
|
208 |
-
|
209 |
-
feedback_button_click = st.button("Worse", key="worse_button")
|
210 |
-
if feedback_button_click:
|
211 |
-
handle_feedback_button_click('worse')
|
|
|
11 |
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
12 |
from io import BytesIO
|
13 |
|
|
|
14 |
openai.api_key = "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"
|
15 |
|
16 |
st.markdown(
|
|
|
43 |
padding: 10px; /* Add padding to the headers */
|
44 |
border-radius: 5px; /* Add border-radius to the headers */
|
45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</style>
|
47 |
""",
|
48 |
unsafe_allow_html=True,
|
|
|
55 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
56 |
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def download_link(content, filename, link_text):
|
59 |
b64 = base64.b64encode(content).decode()
|
60 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
|
|
114 |
# Add personal information to the radiology report
|
115 |
radiology_report_with_personal_info = f"Patient Name: {first_name} {last_name}\nAge: {age}\nGender: {gender}\n\n{radiology_report}"
|
116 |
|
117 |
+
st.header("Radiology Report")
|
118 |
+
st.write(radiology_report_with_personal_info)
|
119 |
+
st.markdown(download_link(save_as_docx(radiology_report_with_personal_info, "radiology_report.docx"), "radiology_report.docx", "Download Report as DOCX"), unsafe_allow_html=True)
|
120 |
+
|
121 |
+
# Feedback buttons
|
122 |
+
st.header("Thanks for your feedback!")
|
123 |
+
feedback_options = ["Better", "Satisfied", "Worse"]
|
124 |
+
selected_feedback = st.radio("Please provide feedback on the generated report:", feedback_options)
|
125 |
+
|
126 |
+
if st.button("Submit Feedback"):
|
127 |
+
st.success("Thanks for providing feedback!")
|
128 |
+
# Implement your feedback handling logic here based on the `selected_feedback` value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|