forked from Jonathan-Adly/clair_streaming_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24e4ff9
commit 810bf3b
Showing
4 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Itnteractions Form</title> | ||
</head> | ||
<body> | ||
<h1>Interactions Form</h1> | ||
{% if error %} | ||
<p style="color: red;">{{ error }}</p> | ||
{% endif %} | ||
<form action="/interactions" method="POST"> | ||
<label for="drugs">Drugs:</label> | ||
<input type="text" id="drugs" name="drugs" required placeholder="atorvastatin, norvasc"> | ||
<p> Enter up to 25 drugs separated by commas</p> | ||
<br><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Listening Drug Interactions Page</title> | ||
</head> | ||
<body> | ||
<h1>Channel Name: {{channel_name}}</h1> | ||
<p>Query_ID = {{query_id}}</p> | ||
<button onclick="start()">Start Listening</button> <!-- button is here for illustration, should call start on window load--> | ||
<p id="error"> </p> | ||
<p id="answer"> Answer: </p> | ||
<p id="references"> References <br> </p> | ||
|
||
|
||
<script src="{{base_url}}/static/js/galenSDK.min.js"> </script> | ||
|
||
<script> | ||
|
||
/* | ||
window.onload = function() { | ||
start(); | ||
}; | ||
*/ | ||
function start() { | ||
// this comes from the galenAI server | ||
var channelName = "{{ channel_name }}" | ||
var queryID = "{{ query_id }}" | ||
|
||
// connect to the channel and listen to events. This must be done first, before calling the ReadyTOListen function | ||
galenConnect(channelName, queryID, function(channel) { | ||
|
||
// start of stream | ||
channel.bind('start', function(data) { | ||
console.log("started stream.."); | ||
//set up your DOM for receiving the data | ||
}); | ||
|
||
// answer | ||
channel.bind("answer", function (data) { | ||
// add the answer to the div | ||
// you will get an answer event if there are no interactions | ||
document.getElementById("answer").innerHTML += data.text; | ||
}); | ||
|
||
// for each interaction, you will get | ||
// new interaction event (for each new interaction) | ||
// drug_pair event (for each interacting drug pair) | ||
// description event (for description of the interaction) | ||
// recommendation event | ||
// reference event | ||
|
||
|
||
channel.bind("new_interaction", function (data) { | ||
let id = data.id; | ||
// make a new div for each new interaction that has drug pair, description, recommendation, references | ||
document.getElementById("answer").innerHTML += `<div id=${id}-drug-pair> "</div>`; | ||
|
||
document.getElementById("answer").innerHTML += `<div id=${id}-description> "</div>`; | ||
document.getElementById("answer").innerHTML += `<div id=${id}-recommendation> "</div>`; | ||
document.getElementById("answer").innerHTML += `<div id=${id}-references> "</div>`; | ||
|
||
}); | ||
|
||
channel.bind("drug_pair", function (data) { | ||
// add the drug pair to the div | ||
|
||
document.getElementById(`${data.id}-drug-pair`).innerHTML += data.text; | ||
}); | ||
|
||
|
||
channel.bind("description", function (data) { | ||
// add the description to the div | ||
document.getElementById(`${data.id}-description`).innerHTML += data.text; | ||
}); | ||
|
||
channel.bind("recommendation", function (data) { | ||
// add the recommendation to the div | ||
document.getElementById(`${data.id}-recommendation`).innerHTML += data.text; | ||
}); | ||
|
||
channel.bind("references", function (data) { | ||
// make a div for title, doi, url, abstract inside references | ||
document.getElementById(`${data.id}-references`).innerHTML += "<div> title:" + data.title + "</div>"; | ||
if (data.doi != null) { | ||
document.getElementById(`${data.id}-references`).innerHTML += "<div> doi:" + data.doi + "</div>"; | ||
document.getElementById(`${data.id}-references`).innerHTML += "<div> url:" + data.url + "</div>"; | ||
document.getElementById(`${data.id}-references`).innerHTML += "<div> abstract:" + data.abstract + "</div>"; | ||
} | ||
}); | ||
|
||
// end | ||
channel.bind("end", function (data) { | ||
channel.unbind(); //unbind the channel when you are done listening | ||
console.log("ended stream.."); | ||
// do something when the stream ends | ||
}); | ||
}); | ||
|
||
|
||
|
||
// Call the ready to listen. | ||
// note - this function, must be called after the channel is connected. | ||
// only call when you are ready to receive events | ||
galenReadyToListen(channelName, queryID); | ||
|
||
|
||
} | ||
|
||
</script> |