Spaces:
Runtime error
Runtime error
Commit
·
64bfafd
1
Parent(s):
07f2c26
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import streamlit as st
|
2 |
-
from streamlit.state import session_state
|
3 |
import pickle
|
4 |
import pandas as pd
|
5 |
import torch
|
@@ -51,7 +50,6 @@ st.markdown(
|
|
51 |
unsafe_allow_html=True,
|
52 |
)
|
53 |
|
54 |
-
|
55 |
device = torch.device("cpu")
|
56 |
|
57 |
testing_df = pd.read_csv("testing_df.csv")
|
@@ -59,13 +57,11 @@ model = CLIPModel().to(device)
|
|
59 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
60 |
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
session_state.chat_history = []
|
68 |
-
|
69 |
|
70 |
def show_predicted_caption(image):
|
71 |
matches = predict_caption(
|
@@ -108,8 +104,6 @@ def download_link(content, filename, link_text):
|
|
108 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
109 |
return href
|
110 |
|
111 |
-
# Initialize the session state
|
112 |
-
init_state()
|
113 |
|
114 |
st.title("RadiXGPT: An Evolution of machine doctors towards Radiology")
|
115 |
|
@@ -150,24 +144,24 @@ if uploaded_file is not None:
|
|
150 |
st.header("1-to-1 Consultation")
|
151 |
st.write("Ask any questions you have about the radiology report:")
|
152 |
|
153 |
-
session_state.user_input = st.text_input("Enter your question:", value=session_state.user_input)
|
154 |
|
155 |
-
if session_state.user_input:
|
156 |
-
session_state.chat_history.append({"user": session_state.user_input})
|
157 |
|
158 |
-
if session_state.user_input.lower() == "thank you":
|
159 |
st.write("Bot: You're welcome! If you have any more questions, feel free to ask.")
|
160 |
-
session_state.user_input = ''
|
161 |
-
session_state.chat_history = []
|
162 |
else:
|
163 |
# Generate the answer to the user's question
|
164 |
-
prompt = f"Answer to the user's question based on the generated radiology report: {session_state.user_input}"
|
165 |
-
for history_item in session_state.chat_history:
|
166 |
prompt += f"\nUser: {history_item['user']}"
|
167 |
if 'bot' in history_item:
|
168 |
prompt += f"\nBot: {history_item['bot']}"
|
169 |
|
170 |
answer = chatbot_response(prompt)
|
171 |
-
session_state.chat_history[-1]["bot"] = answer
|
172 |
st.write(f"Bot: {answer}")
|
173 |
-
session_state.user_input = ''
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import pickle
|
3 |
import pandas as pd
|
4 |
import torch
|
|
|
50 |
unsafe_allow_html=True,
|
51 |
)
|
52 |
|
|
|
53 |
device = torch.device("cpu")
|
54 |
|
55 |
testing_df = pd.read_csv("testing_df.csv")
|
|
|
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 |
+
# Initialize the session state
|
61 |
+
if 'user_input' not in st.session_state:
|
62 |
+
st.session_state.user_input = ''
|
63 |
+
if 'chat_history' not in st.session_state:
|
64 |
+
st.session_state.chat_history = []
|
|
|
|
|
65 |
|
66 |
def show_predicted_caption(image):
|
67 |
matches = predict_caption(
|
|
|
104 |
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
105 |
return href
|
106 |
|
|
|
|
|
107 |
|
108 |
st.title("RadiXGPT: An Evolution of machine doctors towards Radiology")
|
109 |
|
|
|
144 |
st.header("1-to-1 Consultation")
|
145 |
st.write("Ask any questions you have about the radiology report:")
|
146 |
|
147 |
+
st.session_state.user_input = st.text_input("Enter your question:", value=st.session_state.user_input)
|
148 |
|
149 |
+
if st.session_state.user_input:
|
150 |
+
st.session_state.chat_history.append({"user": st.session_state.user_input})
|
151 |
|
152 |
+
if st.session_state.user_input.lower() == "thank you":
|
153 |
st.write("Bot: You're welcome! If you have any more questions, feel free to ask.")
|
154 |
+
st.session_state.user_input = ''
|
155 |
+
st.session_state.chat_history = []
|
156 |
else:
|
157 |
# Generate the answer to the user's question
|
158 |
+
prompt = f"Answer to the user's question based on the generated radiology report: {st.session_state.user_input}"
|
159 |
+
for history_item in st.session_state.chat_history:
|
160 |
prompt += f"\nUser: {history_item['user']}"
|
161 |
if 'bot' in history_item:
|
162 |
prompt += f"\nBot: {history_item['bot']}"
|
163 |
|
164 |
answer = chatbot_response(prompt)
|
165 |
+
st.session_state.chat_history[-1]["bot"] = answer
|
166 |
st.write(f"Bot: {answer}")
|
167 |
+
st.session_state.user_input = ''
|