Spaces:
Sleeping
Sleeping
Commit
·
9551cbd
1
Parent(s):
d0690e4
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,6 @@ from langchain.indexes import VectorstoreIndexCreator
|
|
| 20 |
|
| 21 |
|
| 22 |
os.environ["OPENAI_API_BASE"] = openai.api_type = "azure"
|
| 23 |
-
os.environ["OPENAI_API_KEY"] = openai.api_key = "26d0aaa9d01340cca61da08b29c44069"
|
| 24 |
os.environ["OPENAI_API_BASE"] = openai.api_base = "https://eastus-openai-sean.openai.azure.com/"
|
| 25 |
os.environ["OPENAI_API_VERSION"] = openai.api_version = "2023-03-15-preview"
|
| 26 |
|
|
@@ -31,7 +30,7 @@ def analyze_healthcare_text(text):
|
|
| 31 |
base_url = "https://ta4h-endpoint.cognitiveservices.azure.com/language/analyze-text/jobs"
|
| 32 |
headers = {
|
| 33 |
"Content-Type": "application/json",
|
| 34 |
-
"Ocp-Apim-Subscription-Key": "
|
| 35 |
}
|
| 36 |
|
| 37 |
# Data to be sent in the initial POST request
|
|
@@ -148,11 +147,12 @@ def annotate_text_with_entities(original_text, entities_data):
|
|
| 148 |
original_text = original_text[:start] + entity_html + original_text[end:]
|
| 149 |
|
| 150 |
# Create a color key section
|
| 151 |
-
color_key_section = "<
|
| 152 |
for category, color in category_to_color.items():
|
| 153 |
color_key_section += f'<span style="display: inline-block; background: {color}; width: 1em; height: 1em; margin-right: 0.5em; vertical-align: middle;"></span>{category}<br>'
|
| 154 |
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
return original_text, category_to_color
|
| 158 |
|
|
@@ -242,9 +242,9 @@ if 'colour_to_category' not in st.session_state:
|
|
| 242 |
st.session_state.colour_to_category = 'value'
|
| 243 |
|
| 244 |
with col1:
|
| 245 |
-
col1.subheader("
|
| 246 |
|
| 247 |
-
st.text("Enter your
|
| 248 |
|
| 249 |
dax_input = st.text_area("", height=500)
|
| 250 |
analyze_btn = st.button("Analyze")
|
|
@@ -272,35 +272,28 @@ with col2:
|
|
| 272 |
with st.expander("Show JSON"):
|
| 273 |
st.json(st.session_state.r)
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
with col3:
|
| 279 |
col3.subheader("Copilot Concept")
|
| 280 |
-
|
| 281 |
question = st.text_input("Ask a question to Copilot:")
|
| 282 |
-
|
| 283 |
-
|
| 284 |
grounded = st.selectbox('Would you like to ground the model?', ('Not Grounded', 'Text Analytics for Health', 'Just Text Input', 'Both'))
|
| 285 |
-
|
| 286 |
model = st.selectbox("Model", ["gpt-35-turbo", "gpt-4" ])
|
| 287 |
-
|
| 288 |
ask = st.button("Ask")
|
| 289 |
if grounded != 'Not Grounded':
|
| 290 |
if ask:
|
| 291 |
if grounded == 'Text Analytics for Health':
|
| 292 |
-
total_text = str(st.session_state.
|
| 293 |
-
|
|
|
|
|
|
|
| 294 |
total_text = str(st.session_state.r) + dax_input
|
| 295 |
-
|
| 296 |
-
print(total_text)
|
| 297 |
-
|
| 298 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 299 |
|
| 300 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 301 |
# Set a really small chunk size, just to show.
|
| 302 |
-
chunk_size =
|
| 303 |
-
chunk_overlap =
|
| 304 |
length_function = len,
|
| 305 |
add_start_index = True,
|
| 306 |
)
|
|
@@ -314,12 +307,13 @@ with col3:
|
|
| 314 |
openai_api_type="azure",
|
| 315 |
chunk_size=16,
|
| 316 |
)
|
|
|
|
| 317 |
index = VectorstoreIndexCreator(embedding=embeddings).from_documents(texts)
|
| 318 |
|
| 319 |
st.write(index.query(question, llm=AzureChatOpenAI(temperature=0, deployment_name=model)))
|
| 320 |
-
|
| 321 |
|
| 322 |
elif ask:
|
|
|
|
| 323 |
response = openai.ChatCompletion.create(
|
| 324 |
engine=model,
|
| 325 |
messages = [{"role":"system","content":"You are an AI assistant that helps people find information."}, {"role": "user", "content" : question}],
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
os.environ["OPENAI_API_BASE"] = openai.api_type = "azure"
|
|
|
|
| 23 |
os.environ["OPENAI_API_BASE"] = openai.api_base = "https://eastus-openai-sean.openai.azure.com/"
|
| 24 |
os.environ["OPENAI_API_VERSION"] = openai.api_version = "2023-03-15-preview"
|
| 25 |
|
|
|
|
| 30 |
base_url = "https://ta4h-endpoint.cognitiveservices.azure.com/language/analyze-text/jobs"
|
| 31 |
headers = {
|
| 32 |
"Content-Type": "application/json",
|
| 33 |
+
"Ocp-Apim-Subscription-Key": os.environ["ta4h-api-key"]
|
| 34 |
}
|
| 35 |
|
| 36 |
# Data to be sent in the initial POST request
|
|
|
|
| 147 |
original_text = original_text[:start] + entity_html + original_text[end:]
|
| 148 |
|
| 149 |
# Create a color key section
|
| 150 |
+
color_key_section = "<strong>Color Key:</strong><br>"
|
| 151 |
for category, color in category_to_color.items():
|
| 152 |
color_key_section += f'<span style="display: inline-block; background: {color}; width: 1em; height: 1em; margin-right: 0.5em; vertical-align: middle;"></span>{category}<br>'
|
| 153 |
|
| 154 |
+
|
| 155 |
+
original_text = color_key_section + original_text
|
| 156 |
|
| 157 |
return original_text, category_to_color
|
| 158 |
|
|
|
|
| 242 |
st.session_state.colour_to_category = 'value'
|
| 243 |
|
| 244 |
with col1:
|
| 245 |
+
col1.subheader("Patient Note Input")
|
| 246 |
|
| 247 |
+
st.text("Enter your text input below:")
|
| 248 |
|
| 249 |
dax_input = st.text_area("", height=500)
|
| 250 |
analyze_btn = st.button("Analyze")
|
|
|
|
| 272 |
with st.expander("Show JSON"):
|
| 273 |
st.json(st.session_state.r)
|
| 274 |
|
|
|
|
|
|
|
|
|
|
| 275 |
with col3:
|
| 276 |
col3.subheader("Copilot Concept")
|
|
|
|
| 277 |
question = st.text_input("Ask a question to Copilot:")
|
|
|
|
|
|
|
| 278 |
grounded = st.selectbox('Would you like to ground the model?', ('Not Grounded', 'Text Analytics for Health', 'Just Text Input', 'Both'))
|
|
|
|
| 279 |
model = st.selectbox("Model", ["gpt-35-turbo", "gpt-4" ])
|
|
|
|
| 280 |
ask = st.button("Ask")
|
| 281 |
if grounded != 'Not Grounded':
|
| 282 |
if ask:
|
| 283 |
if grounded == 'Text Analytics for Health':
|
| 284 |
+
total_text = str(st.session_state.r)
|
| 285 |
+
elif grounded == 'Just Text Input':
|
| 286 |
+
total_text = dax_input
|
| 287 |
+
elif grounded == 'Both':
|
| 288 |
total_text = str(st.session_state.r) + dax_input
|
| 289 |
+
|
| 290 |
+
# print(total_text)
|
|
|
|
| 291 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 292 |
|
| 293 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 294 |
# Set a really small chunk size, just to show.
|
| 295 |
+
chunk_size = 8000,
|
| 296 |
+
chunk_overlap = 200,
|
| 297 |
length_function = len,
|
| 298 |
add_start_index = True,
|
| 299 |
)
|
|
|
|
| 307 |
openai_api_type="azure",
|
| 308 |
chunk_size=16,
|
| 309 |
)
|
| 310 |
+
index = ""
|
| 311 |
index = VectorstoreIndexCreator(embedding=embeddings).from_documents(texts)
|
| 312 |
|
| 313 |
st.write(index.query(question, llm=AzureChatOpenAI(temperature=0, deployment_name=model)))
|
|
|
|
| 314 |
|
| 315 |
elif ask:
|
| 316 |
+
print("not grounded")
|
| 317 |
response = openai.ChatCompletion.create(
|
| 318 |
engine=model,
|
| 319 |
messages = [{"role":"system","content":"You are an AI assistant that helps people find information."}, {"role": "user", "content" : question}],
|