Spaces:
Runtime error
Runtime error
Commit
·
ad61148
1
Parent(s):
473583b
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,6 @@ import numpy as np
|
|
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
|
@@ -76,13 +74,20 @@ def chatbot_response(prompt):
|
|
76 |
)
|
77 |
return response.choices[0].text.strip()
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
return buffer
|
86 |
|
87 |
|
88 |
st.title("RadiXGPT: An Evolution of machine doctors towrads Radiology")
|
@@ -101,8 +106,8 @@ if uploaded_file is not None:
|
|
101 |
st.success(f"Caption: {caption}")
|
102 |
|
103 |
# Add the OpenAI API call here and generate the radiology report
|
104 |
-
radiology_report = f"Write Complete Radiology Report for this: {caption}"
|
105 |
-
container = st.
|
106 |
with container:
|
107 |
st.header("Radiology Report")
|
108 |
st.write(radiology_report)
|
@@ -122,7 +127,7 @@ if uploaded_file is not None:
|
|
122 |
state.chat_history.append("Bot: You're welcome! If you have any more questions, feel free to ask.")
|
123 |
else:
|
124 |
# Add the OpenAI API call here and generate the answer to the user's question
|
125 |
-
answer = f"Answer to the user's question based on the generated radiology report: {user_input}"
|
126 |
state.chat_history.append(f"Bot: {answer}")
|
127 |
|
128 |
# Display the chat history
|
|
|
7 |
from main import predict_caption, CLIPModel, get_text_embeddings
|
8 |
import openai
|
9 |
import base64
|
|
|
|
|
10 |
import docx
|
11 |
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
12 |
from io import BytesIO
|
|
|
74 |
)
|
75 |
return response.choices[0].text.strip()
|
76 |
|
77 |
+
# Add this function to your code
|
78 |
+
def save_as_docx(text, filename):
|
79 |
+
document = Document()
|
80 |
+
document.add_paragraph(text)
|
81 |
+
with BytesIO() as output:
|
82 |
+
document.save(output)
|
83 |
+
output.seek(0)
|
84 |
+
return output.getvalue()
|
85 |
|
86 |
+
# Add this function to your code
|
87 |
+
def download_link(content, filename, link_text):
|
88 |
+
b64 = base64.b64encode(content).decode()
|
89 |
+
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{link_text}</a>'
|
90 |
+
return href
|
|
|
91 |
|
92 |
|
93 |
st.title("RadiXGPT: An Evolution of machine doctors towrads Radiology")
|
|
|
106 |
st.success(f"Caption: {caption}")
|
107 |
|
108 |
# Add the OpenAI API call here and generate the radiology report
|
109 |
+
radiology_report = generate_radiology_report(f"Write Complete Radiology Report for this: {caption}")
|
110 |
+
container = st.container()
|
111 |
with container:
|
112 |
st.header("Radiology Report")
|
113 |
st.write(radiology_report)
|
|
|
127 |
state.chat_history.append("Bot: You're welcome! If you have any more questions, feel free to ask.")
|
128 |
else:
|
129 |
# Add the OpenAI API call here and generate the answer to the user's question
|
130 |
+
answer = chatbot_response(f"Answer to the user's question based on the generated radiology report: {user_input}")
|
131 |
state.chat_history.append(f"Bot: {answer}")
|
132 |
|
133 |
# Display the chat history
|