Singularity666 commited on
Commit
a06bc99
·
1 Parent(s): 64bfafd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -23
app.py CHANGED
@@ -50,6 +50,7 @@ st.markdown(
50
  unsafe_allow_html=True,
51
  )
52
 
 
53
  device = torch.device("cpu")
54
 
55
  testing_df = pd.read_csv("testing_df.csv")
@@ -57,12 +58,6 @@ model = CLIPModel().to(device)
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(
68
  image, model, text_embeddings, testing_df["caption"]
@@ -104,7 +99,6 @@ def download_link(content, filename, link_text):
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
 
110
  # Collect user's personal information
@@ -140,28 +134,26 @@ if uploaded_file is not None:
140
  st.write(radiology_report_with_personal_info)
141
  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)
142
 
143
- # Modify the 1-to-1 consultation section
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 = ''
 
50
  unsafe_allow_html=True,
51
  )
52
 
53
+
54
  device = torch.device("cpu")
55
 
56
  testing_df = pd.read_csv("testing_df.csv")
 
58
  model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
59
  text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
60
 
 
 
 
 
 
 
61
  def show_predicted_caption(image):
62
  matches = predict_caption(
63
  image, model, text_embeddings, testing_df["caption"]
 
99
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
100
  return href
101
 
 
102
  st.title("RadiXGPT: An Evolution of machine doctors towards Radiology")
103
 
104
  # Collect user's personal information
 
134
  st.write(radiology_report_with_personal_info)
135
  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)
136
 
137
+ # Add the chatbot functionality
138
  st.header("1-to-1 Consultation")
139
  st.write("Ask any questions you have about the radiology report:")
140
+
141
+ user_input = st.text_input("Enter your question:")
142
+ chat_history = []
143
+
144
+ if user_input:
145
+ chat_history.append({"user": user_input})
146
+
147
+ if user_input.lower() == "thank you":
148
  st.write("Bot: You're welcome! If you have any more questions, feel free to ask.")
 
 
149
  else:
150
  # Generate the answer to the user's question
151
+ prompt = f"Answer to the user's question based on the generated radiology report: {user_input}"
152
+ for history_item in chat_history:
153
  prompt += f"\nUser: {history_item['user']}"
154
  if 'bot' in history_item:
155
  prompt += f"\nBot: {history_item['bot']}"
156
+
157
  answer = chatbot_response(prompt)
158
+ chat_history[-1]["bot"] = answer
159
+ st.write(f"Bot: {answer}")