Singularity666 commited on
Commit
36b2997
·
1 Parent(s): 6d4a896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -7,9 +7,11 @@ import numpy as np
7
  from main import predict_caption, CLIPModel, get_text_embeddings
8
  import openai
9
  import base64
10
- from io import BytesIO
11
  from reportlab.lib.pagesizes import letter
12
  from reportlab.pdfgen import canvas
 
 
 
13
 
14
  # Set up OpenAI API
15
  openai.api_key = "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"
@@ -90,32 +92,28 @@ if uploaded_file is not None:
90
  st.image(image, caption="Uploaded Image", use_column_width=True)
91
  st.write("")
92
 
93
- if st.button("Generate Report"):
94
- with st.spinner("Generating Report...hold on"):
95
  image_np = np.array(image)
96
  caption = show_predicted_caption(image_np)
97
  st.success(f"Caption: {caption}")
98
 
99
- prompt = f"Write Complete Radiology Report for this: {caption}"
100
- report = generate_radiology_report(prompt)
101
-
102
- st.markdown("<h2>Generated Radiology Report</h2>", unsafe_allow_html=True)
103
- st.markdown(f"<div class='container'>{report}</div>", unsafe_allow_html=True)
104
-
105
- # PDF download
106
- buffer = BytesIO()
107
- pdf_buffer = create_pdf(report, buffer)
108
- b64 = base64.b64encode(pdf_buffer.getvalue()).decode()
109
- href = f'<a href="data:application/octet-stream;base64,{b64}" download="Radiology_Report.pdf">Download Radiology Report as PDF</a>'
110
- st.markdown(href, unsafe_allow_html=True)
111
-
112
- # Chatbot for consultation
113
- st.markdown("<h2>Need help understanding the Radiological Report?</h2>", unsafe_allow_html=True)
114
- st.write("Ask your queries here:")
115
- user_question = st.text_input("")
116
-
117
- if st.button("Get Help"):
118
- chat_prompt = f"The generated radiology report is: {report}. User asks: {user_question}"
119
- chat_answer = chatbot_response(chat_prompt)
120
- st.markdown("<h3>Answer:</h3>", unsafe_allow_html=True)
121
- st.write(chat_answer)
 
7
  from main import predict_caption, CLIPModel, get_text_embeddings
8
  import openai
9
  import base64
 
10
  from reportlab.lib.pagesizes import letter
11
  from reportlab.pdfgen import canvas
12
+ import docx
13
+ from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
14
+ from io import BytesIO
15
 
16
  # Set up OpenAI API
17
  openai.api_key = "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"
 
92
  st.image(image, caption="Uploaded Image", use_column_width=True)
93
  st.write("")
94
 
95
+ if st.button("Generate Caption"):
96
+ with st.spinner("Generating caption..."):
97
  image_np = np.array(image)
98
  caption = show_predicted_caption(image_np)
99
  st.success(f"Caption: {caption}")
100
 
101
+ # Add the OpenAI API call here and generate the radiology report
102
+ radiology_report = f"Write Complete Radiology Report for this: {caption}"
103
+ container = st.beta_container()
104
+ with container:
105
+ st.header("Radiology Report")
106
+ st.write(radiology_report)
107
+ st.markdown(download_link(save_as_docx(radiology_report, "radiology_report.docx"), "radiology_report.docx", "Download Report as DOCX"), unsafe_allow_html=True)
108
+
109
+ # Add the chatbot functionality
110
+ st.header("1-to-1 Consultation")
111
+ st.write("Ask any questions you have about the radiology report:")
112
+ user_input = st.text_input("Enter your question:")
113
+ if user_input:
114
+ if user_input.lower() == "thank you":
115
+ st.write("You're welcome! If you have any more questions, feel free to ask.")
116
+ else:
117
+ # Add the OpenAI API call here and generate the answer to the user's question
118
+ answer = f"Answer to the user's question based on the generated radiology report: {user_input}"
119
+ st.write(answer)