Spaces:
Runtime error
Runtime error
Commit
·
5602714
1
Parent(s):
dfe6abe
Update app.py
Browse files
app.py
CHANGED
@@ -83,96 +83,6 @@ last_name = st.text_input("Last Name")
|
|
83 |
age = st.number_input("Age", min_value=0, max_value=120, value=25, step=1)
|
84 |
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
85 |
|
86 |
-
st.write("Upload Scan to get Radiological Report:")
|
87 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
88 |
-
if uploaded_file is not None:
|
89 |
-
image = Image.open(uploaded_file)
|
90 |
-
st.image(image
|
91 |
-
import streamlit as st
|
92 |
-
import pickle
|
93 |
-
import pandas as pd
|
94 |
-
import torch
|
95 |
-
from PIL import Image
|
96 |
-
import numpy as np
|
97 |
-
from main import predict_caption, CLIPModel, get_text_embeddings
|
98 |
-
import openai
|
99 |
-
import base64
|
100 |
-
from docx import Document
|
101 |
-
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
102 |
-
from io import BytesIO
|
103 |
-
|
104 |
-
# Set up OpenAI API
|
105 |
-
openai.api_key = "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"
|
106 |
-
|
107 |
-
# Custom CSS for the page
|
108 |
-
st.markdown(
|
109 |
-
"""
|
110 |
-
<style>
|
111 |
-
body {
|
112 |
-
background-color: transparent;
|
113 |
-
}
|
114 |
-
.container {
|
115 |
-
display: flex;
|
116 |
-
justify-content: center;
|
117 |
-
align-items: center;
|
118 |
-
background-color: rgba(255, 255, 255, 0.7);
|
119 |
-
border-radius: 15px;
|
120 |
-
padding: 20px;
|
121 |
-
}
|
122 |
-
.stApp {
|
123 |
-
background-color: transparent;
|
124 |
-
}
|
125 |
-
.stText, .stMarkdown, .stTextInput>label, .stButton>button>span {
|
126 |
-
color: #1c1c1c !important; /* Set the dark text color for text elements */
|
127 |
-
}
|
128 |
-
.stButton>button>span {
|
129 |
-
color: initial !important; /* Reset the text color for the 'Generate Caption' button */
|
130 |
-
}
|
131 |
-
.stMarkdown h1, .stMarkdown h2 {
|
132 |
-
color: #ff6b81 !important; /* Set the text color of h1 and h2 elements to soft red-pink */
|
133 |
-
font-weight: bold; /* Set the font weight to bold */
|
134 |
-
border: 2px solid #ff6b81; /* Add a bold border around the headers */
|
135 |
-
padding: 10px; /* Add padding to the headers */
|
136 |
-
border-radius: 5px; /* Add border-radius to the headers */
|
137 |
-
}
|
138 |
-
</style>
|
139 |
-
""",
|
140 |
-
unsafe_allow_html=True,
|
141 |
-
)
|
142 |
-
|
143 |
-
device = torch.device("cpu")
|
144 |
-
|
145 |
-
testing_df = pd.read_csv("testing_df.csv")
|
146 |
-
model = CLIPModel().to(device)
|
147 |
-
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
148 |
-
text_embeddings = torch.load('saved_text_embeddings.pt', map_location=device)
|
149 |
-
|
150 |
-
def show_predicted_caption(image, second_attempt=False):
|
151 |
-
matches = predict_caption(
|
152 |
-
image, model, text_embeddings, testing_df["caption"], second_attempt
|
153 |
-
)[0 if not second_attempt else 1]
|
154 |
-
return matches
|
155 |
-
|
156 |
-
def generate_radiology_report(prompt):
|
157 |
-
response = openai.Completion.create(
|
158 |
-
engine="text-davinci-003",
|
159 |
-
prompt=prompt,
|
160 |
-
max_tokens=800,
|
161 |
-
n=1,
|
162 |
-
stop=None,
|
163 |
-
temperature=1,
|
164 |
-
)
|
165 |
-
return response.choices[0].text.strip()
|
166 |
-
|
167 |
-
st.title("RadiXGPT: An Evolution of machine doctors towards Radiology")
|
168 |
-
|
169 |
-
# Collect user's personal information
|
170 |
-
st.subheader("Personal Information")
|
171 |
-
first_name = st.text_input("First Name")
|
172 |
-
last_name = st.text_input("Last Name")
|
173 |
-
age = st.number_input("Age", min_value=0, max_value=120, value=25, step=1)
|
174 |
-
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
175 |
-
|
176 |
st.write("Upload Scan to get Radiological Report:")
|
177 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
178 |
if uploaded_file is not None:
|
@@ -215,4 +125,4 @@ if uploaded_file is not None:
|
|
215 |
st.success("Thank you for your feedback! Your input helps us improve the RadiXGPT system.")
|
216 |
# Add your feedback processing logic here
|
217 |
# This could include updating the model with the new information,
|
218 |
-
# logging the feedback, or triggering an alert for manual review
|
|
|
83 |
age = st.number_input("Age", min_value=0, max_value=120, value=25, step=1)
|
84 |
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
st.write("Upload Scan to get Radiological Report:")
|
87 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
88 |
if uploaded_file is not None:
|
|
|
125 |
st.success("Thank you for your feedback! Your input helps us improve the RadiXGPT system.")
|
126 |
# Add your feedback processing logic here
|
127 |
# This could include updating the model with the new information,
|
128 |
+
# logging the feedback, or triggering an alert for manual review
|