Skip to content

Commit

Permalink
NN-368 Removed Chatbot & Implemented routing section
Browse files Browse the repository at this point in the history
-removed chatbot from backend & frontend
-added information from string
-added routing section
  • Loading branch information
TripZz committed Nov 2, 2023
1 parent 6fe1fe6 commit 034717a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 108 deletions.
18 changes: 0 additions & 18 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ def proteins_enrichment():
json_str = json.dumps(list_enrichment.to_dict("records"), ensure_ascii=False, separators=(",", ":"))
return Response(json_str, mimetype="application/json")

@app.route("/api/subgraph/chatbot", methods=["POST"])
def proteins_chatbot():
message = request.form.get("message")

g4f.debug.logging = True # enable logging
g4f.check_version = False # Disable automatic version checking
print(g4f.version) # check version
print(g4f.Provider.Ails.params) # supported args

# normal response
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
provider=g4f.Provider.Yqcloud,
messages=[{"role": "user", "content": message}]
) # alternative model setting#
if response != None:
return Response(str(response), mimetype="application/json")

# ====================== Subgraph API ======================
# request comes from home.js
# TODO Refactor this
Expand Down
72 changes: 5 additions & 67 deletions frontend/src/components/pane/modules/node/ChatbotInformation.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<template>
<div id="chatbot">
<div v-if="await_answer==true" class="loading_pane" ></div>
<div v-if="await_answer==false">
<div class="text">{{ protein_information }}</div>
<div id="search-1" v-if="protein_information" v-on:click="ask_question(protein_questions[0])">
<img class="search-field-icon" src="@/assets/toolbar/search.png">
<span>{{ protein_questions[0] }}</span>
</div>
<div id="search-2" v-if="protein_information" v-on:click="ask_question(protein_questions[1])">
<img class="search-field-icon" src="@/assets/toolbar/search.png">
<span>{{ protein_questions[1] }}</span>
</div>
</div>
<div class="text">{{ protein_information }}</div>
</div>
</template>

Expand All @@ -23,50 +12,16 @@ export default {
data() {
return {
protein_information: "",
protein_questions:"",
await_answer:false,
protein_name:''
}
},
watch:{
active_node(){
if (this.active_node == null) {
return;
}
this.protein_name = this.active_node.attributes["Name"]
this.protein_information = ""
this.generate_informations(`What is Gene/Protein ${this.protein_name} in 2 Sentences?`, false)
this.generate_informations(`Give me 2 common corrolated questions to Gene ${this.protein_name} with maximum 7 Words!`, true)
}
if (this.active_node == null) return
this.protein_information = this.active_node.attributes['Description']
},
},
methods:{
generate_informations(message, question){
var com = this
//Adding proteins and species to formdata
var formData = new FormData()
formData.append('message', message)
this.await_answer = true
//POST request for generating pathways
com.sourceToken = this.axios.CancelToken.source();
com.axios
.post("api/subgraph/chatbot", formData, { cancelToken: com.sourceToken.token })
.then((response) => {
if(!question) {
this.protein_information = response.data
this.await_answer = false
}
else this.protein_questions = response.data.split(/\d+\.\s+/).filter(question => question !== '');
})
},
ask_question(message){
this.generate_informations(`${message} in correlation with Gene ${this.protein_name}. Do a short answer` , false)
this.generate_informations(`Give me 2 question with maximal 7 words correlated to your previous answer: ${this.protein_information}` , true)
}
}
}
</script>
Expand All @@ -82,15 +37,10 @@ export default {
padding: 0% 2% 2% 2%;
}
#chatbot .loading_pane {
margin-top: 40%;
}
#chatbot .text {
width: 100%;
top: 16%;
height: 50%;
height: 80%;
overflow-y: scroll;
position: absolute;
padding: 0 5% 0 2%;
Expand All @@ -100,18 +50,6 @@ export default {
display: none;
}
#chatbot #search-1 {
position: absolute;
top: 72%;
width:100%;
}
#chatbot #search-2 {
position: absolute;
top: 84%;
width:100%;
}
#chatbot #search-1 span,
#chatbot #search-2 span {
margin-left: 10%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default {
#statistics {
width: 100%;
height: 100%;
top: 16.35%;
top: 20.35%;
position: absolute;
font-family: 'ABeeZee', sans-serif;
padding: 0% 2% 2% 2%;
Expand Down Expand Up @@ -103,7 +103,7 @@ export default {
}
#statistics .network-results {
height: 69%;
height: 67%;
overflow: scroll;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pane/modules/node/NodeConnections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export default {
#connect {
width: 100%;
height: 100%;
top: 16.35%;
top: 18.35%;
position: absolute;
font-family: 'ABeeZee', sans-serif;
padding: 0% 2% 2% 2%;
}
#connect .network-results {
height: 70%;
height: 68%;
overflow: scroll;
}
</style>
27 changes: 8 additions & 19 deletions frontend/src/components/pane/modules/node/NodePane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<span>routing</span>
</div>
<div class="subsection-main">
<RoutingNode
:active_node='active_node'
:gephi_data='gephi_data'
></RoutingNode>
</div>
</div>
</div>
Expand All @@ -48,6 +52,7 @@
import NetworkStatistics from '@/components/pane/modules/node/NetworkStatistics.vue'
import NodeConnections from '@/components/pane/modules/node/NodeConnections.vue'
import ChatbotInformation from '@/components/pane/modules/node/ChatbotInformation.vue'
import RoutingNode from '@/components/pane/modules/node/RoutingNode.vue'
export default {
name: 'NodePane',
Expand All @@ -56,7 +61,8 @@ export default {
components: {
NetworkStatistics,
ChatbotInformation,
NodeConnections
NodeConnections,
RoutingNode
},
data() {
Expand All @@ -70,9 +76,6 @@ export default {
imageSrc: require('@/assets/pane/protein-icon.png')
},
nodes: this.gephi_data.nodes,
selected_protein: null,
path: true,
protein_name:""
}
},
watch: {
Expand Down Expand Up @@ -116,22 +119,8 @@ export default {
select_node(value) {
this.emitter.emit("searchNode", value);
},
retrieve_path() {
this.path = true
if(this.selected_protein == null) {
this.emitter.emit("reset_protein", this.active_node)
return
}
this.emitter.emit("searchPathway", {"source":this.active_node.id ,"target": this.selected_protein.id});
},
},
mounted(){
this.emitter.on("emptySet", (state) => {
this.path = state
});
}
}
</script>

Expand Down Expand Up @@ -196,7 +185,7 @@ export default {
}
#routing {
height: 18%;
height: 20%;
}
#network {
Expand Down
108 changes: 108 additions & 0 deletions frontend/src/components/pane/modules/node/RoutingNode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<div id="route">
<div class="search-field">
<img class="search-field-icon" src="@/assets/toolbar/search.png">
<input type="text" v-model="search_raw" class="empty" placeholder="enter target protein" @keyup.enter="retrieve_path(search_raw)"/>
</div>
<div class="request_answer">
<span>connection: {{ path }}</span>
</div>
</div>
</template>

<script>
export default {
name: 'RoutingNode',
props: ['active_node','gephi_data'],
data() {
return {
search_raw:"",
path: null,
target_prot: null,
}
},
mounted(){
this.emitter.on("emptySet", (state) => {
this.path = state
});
},
watch:{
active_node(){
if (!this.active_node) {
this.search_raw = ''
this.path = false
}
}
},
methods:{
retrieve_path(target) {
if(!target) {
this.emitter.emit("reset_protein", this.active_node)
return
}
this.target_prot = this.gephi_data.nodes.filter(function(node) {
return (node.attributes['Name'].toLowerCase() === target.toLowerCase());
})[0];
if(!this.target_prot) {
this.path=false
return
}
this.emitter.emit("searchPathway", {"source":this.active_node.id ,"target": this.target_prot.id});
},
},
}
</script>

<style>
#route {
width: 100%;
height: 100%;
top: 25%;
position: absolute;
display: flex;
justify-content: center;
font-family: 'ABeeZee', sans-serif;
padding: 0% 2% 2% 2%;
}
#route .search-field{
width: 70%;
height: 25%;
display: flex;
border-radius: 5px;
background: rgba(222, 222, 222, 0.3);
position: absolute;
align-items: center;
align-content: center;
justify-content: center;
z-index: 999;
}
#route .search-field input[type=text] {
margin-left: 10%;
font-size: 0.7vw;
width: 83%;
background: none;
color: white;
cursor: default;
font-family: 'ABeeZee', sans-serif;
border: none;
}
.request_answer {
top: 30%;
left: 20%;
position: absolute;
display: block;
font-size: 0.7vw;
}
.request_answer span{
color: white;
float: left;
clear: left;
}
</style>
1 change: 1 addition & 0 deletions frontend/src/components/visualization/MainVis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ export default {
const endNode = sigma_instance.graph.getNodeFromIndex(endID);
const paths = new Set(sigma_instance.graph.astar(startNode.id, endNode.id));
if(paths.size == 0) this.emitter.emit("emptySet", false);
else this.emitter.emit("emptySet", true);
sigma_instance.graph.nodes().forEach(n =>{
if(paths.has(n)){
Expand Down

0 comments on commit 034717a

Please sign in to comment.