Spaces:
Runtime error
Runtime error
Commit
·
ddab8d7
1
Parent(s):
eace5c6
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import pickle
|
3 |
import pandas as pd
|
4 |
import torch
|
@@ -56,6 +57,23 @@ model = CLIPModel().to(device)
|
|
56 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
57 |
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def download_link(content, filename, link_text):
|
60 |
b64 = base64.b64encode(content).decode()
|
61 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
@@ -110,8 +128,10 @@ if uploaded_file is not None:
|
|
110 |
if st.button("Generate Caption"):
|
111 |
with st.spinner("Generating caption..."):
|
112 |
image_np = np.array(image)
|
113 |
-
|
114 |
-
|
|
|
|
|
115 |
st.success(f"Caption: {caption}")
|
116 |
|
117 |
# Generate the radiology report
|
@@ -125,10 +145,13 @@ if uploaded_file is not None:
|
|
125 |
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)
|
126 |
|
127 |
# Feedback buttons
|
128 |
-
st.header("
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit.session_state import SessionState
|
3 |
import pickle
|
4 |
import pandas as pd
|
5 |
import torch
|
|
|
57 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
58 |
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
59 |
|
60 |
+
# New function to handle feedback system
|
61 |
+
def handle_feedback(session_state):
|
62 |
+
if session_state.caption_index < len(session_state.generated_captions) - 1:
|
63 |
+
session_state.caption_index += 1
|
64 |
+
new_caption = session_state.generated_captions[session_state.caption_index]
|
65 |
+
return new_caption
|
66 |
+
else:
|
67 |
+
st.warning("No more captions available to regenerate the report.")
|
68 |
+
return session_state.generated_captions[session_state.caption_index]
|
69 |
+
|
70 |
+
# Initialize the session state
|
71 |
+
if "caption_index" not in st.session_state:
|
72 |
+
st.session_state.caption_index = 0
|
73 |
+
|
74 |
+
if "generated_captions" not in st.session_state:
|
75 |
+
st.session_state.generated_captions = []
|
76 |
+
|
77 |
def download_link(content, filename, link_text):
|
78 |
b64 = base64.b64encode(content).decode()
|
79 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
|
|
128 |
if st.button("Generate Caption"):
|
129 |
with st.spinner("Generating caption..."):
|
130 |
image_np = np.array(image)
|
131 |
+
captions = show_predicted_caption(image_np, top_k=2)
|
132 |
+
st.session_state.generated_captions = captions
|
133 |
+
caption = captions[st.session_state.caption_index]
|
134 |
+
|
135 |
st.success(f"Caption: {caption}")
|
136 |
|
137 |
# Generate the radiology report
|
|
|
145 |
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)
|
146 |
|
147 |
# Feedback buttons
|
148 |
+
st.header("Feedback")
|
149 |
+
if st.button("Not Satisfied"):
|
150 |
+
new_caption = handle_feedback(st.session_state)
|
151 |
+
if new_caption:
|
152 |
+
# Generate new radiology report
|
153 |
+
radiology_report = generate_radiology_report(f"Write Complete Radiology Report for this with clinical info, subjective, Assessment, Finding, Impressions, Conclusion and more in proper order : {new_caption}")
|
154 |
+
radiology_report_with_personal_info = f"Patient Name: {first_name} {last_name}\nAge: {age}\nGender: {gender}\n\n{radiology_report}"
|
155 |
+
st.header("New Radiology Report")
|
156 |
+
st.write(radiology_report_with_personal_info)
|
157 |
+
st.markdown(download_link(save_as_docx(radiology_report_with_personal_info, "radiology_report.docx"), "radiology_report.docx", "Download New Report as DOCX"), unsafe_allow_html=True)
|