-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlitApp.py
More file actions
677 lines (537 loc) · 29.2 KB
/
Copy pathstreamlitApp.py
File metadata and controls
677 lines (537 loc) · 29.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
import streamlit as st
from codebase import *
import pandas as pd
import time
import os
working_dir = os.getcwd()
input_path = working_dir + "/ontologies/KnowledgeGraph_inferred.owl"
output_path = working_dir + "/ontologies/KnowledgeGraph_inferred.owl"
# streamlit run D:\Github\MetaDataExtract\streamlitApp.py
# streamlit run .\streamlitApp.py
#./ontologies/KnowledgeGraph_no_users.owl
if "result_json" not in st.session_state:
st.session_state.result_json = {
"foaf:name":None,
"foaf:Organization":None,
"foaf:age":None,
"voc4cat:ReactionName":None,
"voc4cat:CatalysisResearchField":None
}
if "input_json" not in st.session_state:
st.session_state.input_json = {
"foaf:name":None,
"foaf:Organization":None,
"foaf:age":None,
"voc4cat:ReactionName":None,
"voc4cat:CatalysisResearchField":None
}
if "iri_json" not in st.session_state:
st.session_state.iri_json = {
"foaf:name":"http://xmlns.com/foaf/spec/#term_name",
"foaf:Organization":"http://xmlns.com/foaf/spec/#term_Organization",
"foaf:age":"http://xmlns.com/foaf/spec/#term_age",
"voc4cat:ReactionName":"https://w3id.org/nfdi4cat/voc4cat_0007009",
"voc4cat:CatalysisResearchField":"https://w3id.org/nfdi4cat/voc4cat_0000196"
}
####
if "KGdataReady" not in st.session_state:
st.session_state.KGdataReady = False
with open('./config.json', 'r') as f:
config = json.load(f)
globals().update(config)
##
#"ontology_url": "http://xmlns.com/foaf/spec/index.rdf",
#"base_ontology": "./ontologies/BaseOntology.owl",
##
# Load ontology
onto_world = owlready2.World()
onto = onto_world.get_ontology(base_ontology).load()
onto.name = "onto"
for i in list(st.session_state.result_json.keys()):
st.session_state[i] = None
st.session_state[f"saved_{i}"] = None
if "input_name" not in st.session_state:
st.session_state.input_name = None
if "input_org" not in st.session_state:
st.session_state.input_org = None
if "input_age" not in st.session_state:
st.session_state.input_age = None
if "input_reac" not in st.session_state:
st.session_state.input_reac = None
if "input_research" not in st.session_state:
st.session_state.input_research = None
def metadata_validation():
#contained_counter = 0
miss_list = []
err_list = list(st.session_state.result_json.keys()) # name, org, age, reac, research
for i in err_list:
if st.session_state.result_json[i] is None or st.session_state.result_json[i] == "":
miss_list.append(i)
elif i != "foaf:age" and str(st.session_state.result_json[i]).isdigit():
miss_list.append(i)
elif i == "foaf:age" and not str(st.session_state.result_json[i]).isdigit():
miss_list.append(i)
else:
pass
#miss_list = [i for i in err_list if st.session_state.result_json[i] is None]
return miss_list
def metadata_validation_userInput():
miss_list = metadata_validation()
out_dict = {}
if len(miss_list) == 0:
st.success("No Entries missing. You can add the metadata to the knowledge graph.")
else:
for i in miss_list:
#st.warning(f"Mandatory entry missing: Please provide a {i}:")
# if "submitted" not in st.session_state:
# st.session_state.submitted = False
## Alex
#text_input = st.text_input(f"Enter {i}", "", label_visibility="collapsed")#, label_visibility="collapsed")# key=f"input_{i}"), on_change=submit()
#st.write(f"You entered: {text_input}")
#if not st.session_state.submitted:
# st.text_input("Enter something:", key=f"input_{i}", on_change=submit(i))
#else:
# st.success(f"You entered: {st.session_state[f"saved_{i}"]}")
#st.session_state.input_name = st.text_input(f"Your {i}:","", label_visibility="collapsed")
#variable = st.session_state.input_name if st.session_state.input_name.strip() else st.session_state.result_json[i]
#st.session_state.result_json[i] = variable
#miss_list = metadata_validation()
out_dict[i] = st.session_state.input_json[i]
for key, value in out_dict.items():
#check if value is not empty and not a number, except for foaf:age
if value and (key != "foaf:age" and not str(value).isdigit()):
st.session_state.result_json[key] = value
#st.session_state[f"saved_{key}"] = value
elif key == "foaf:age" and str(value).isdigit():
st.session_state.result_json[key] = value
#st.session_state[f"saved_{key}"] = value
else:
if key == "foaf:age":
st.error("Please enter a valid age (a number).")
else:
st.error(f"Please enter a valid {key}.")
#st.session_state.result_json[key] = None
#
# raise error
#st.session_state.result_json = {k: v for k, v in st.session_state.result_json.items() if v is not None}
return out_dict
st.set_page_config(page_title="DEMO - MetaExtract4Cat", page_icon="📄", layout="wide")
#st.session_state.result_json = {}
col1, col2 = st.columns([0.5, 7])
with col1:
st.image("./MetaExtract4Cat.svg", width=120)
with col2:
st.title("DEMO - MetaExtract4Cat")
#st.write("Please write a short text about you containing: Your name, your organization, your age (you are allowed to lie here😉), and your favorite reaction name and favourite catalysis research topic.")
# Input box
col3, col4, col5 = st.columns([3, 3, 3])
with col3:
st.header(":blue[Metadata Extraction]", divider="blue")
user_input = st.text_area("Please write a short text about you containing: Your name, your organization, your age (you are allowed to be flexible here😉), and your favorite reaction name and catalysis research field you work with or like the most.", "My favorite reaction is the Maillard reaction because it results in very tasty food, also I like biocatalysis most. My name is Alexander Sommer-Behr and I'm a Postdoc at TU Dortmund University.")
# Button
if st.button("Digest Data"):
if user_input.strip():
start = time.time()
st.session_state.result_json = call_ollama(user_input)
end = time.time()
#st.write("processing time " + str(round(end - start, 3)) + " s" )
st.session_state.success = st.success("Metadata found: (processing time " + str(round(end - start, 2)) + " s)" )
st.write(st.session_state.result_json)
else:
st.warning("Please enter some text first!")
with col4:
#Alex
#vaList = metadata_validator()
#col4ba, col4bb = st.columns([2,2])
#with col4bb:
st.header(":red[Metadata Processing]", divider="red")
urlfoaf = "http://xmlns.com/foaf/spec/"
urlv4c = "https://w3id.org/nfdi4cat/voc4cat"
col4a,col4b = st.columns([2,2])
with col4a:
st.write("foaf = [Friend of a friend ontology](%s)"% urlfoaf)#+ " | voc4cat = [Voc4cat vocabulary](%s)"% urlv4c)
with col4b:
st.write("voc4cat = [Voc4cat vocabulary](%s)"% urlv4c)
# with col4b:
# if st.button("Validate Metadata"):
# #added_dict = metadata_validation_userInput()#metadata_validation_userInput()
# mlist = metadata_validation()
# #st.write(mlist)
# if len(mlist) == 0:
# st.session_state.KGdataReady = True
# #st.success("No Entries missing. You can add the metadata to the knowledge graph.")
if st.button("Add to local Knowledge Graph"):
#print("\n\n\n adding to KG\n\n\n")
if st.session_state.KGdataReady == True:
#print("\n\n\n adding to KG\n\n\n")
#with onto:
onto = dict2kg(onto, st.session_state.result_json)
with onto:
onto.save(file="./ontologies/KnowledgeGraph_inferred.owl", format="rdfxml")
st.success("Metadata added to the knowledge graph!")
bashCommand = f"""java -jar {working_dir}/robot/robot.jar reason --reasoner hermit --axiom-generators "PropertyAssertion ClassAssertion PropertyAssertion ObjectPropertyRange InverseObjectProperties ObjectPropertyDomain" --exclude-tautologies all --input {input_path} reduce --output {output_path}"""
os.system(bashCommand)
# onto_world.close
# onto_world = owlready2.World()
# onto = onto_world.get_ontology(output_path).load()
# onto.name = "onto"
#print(bashCommand)
else:
st.error("Metadata not valid yet. Please enter (proper) data.")
for key, val in st.session_state.result_json.items():
#
## Alex
if key == "foaf:Organization":
#st.markdown(f":small[[{key}]({st.session_state.iri_json[key]})]")
org_list = list(kg_query(onto_world, "", 4)["org"])
#col4minia, col4minib = st.columns([2,2])
# with col4minia:
if "options_org" not in st.session_state:
st.session_state.options_org = org_list
if type(val) == list:
sel_orgs = [i for i in val if i in org_list]
for orga in sel_orgs:
if orga not in st.session_state.options_org:
st.session_state.options_org.append(orga)
elif val in org_list:
sel_orgs = [val]
if val not in st.session_state.options_org:
st.session_state.options_org.append(val)
else:
sel_orgs = []
#sel_orgs = [v for v in sel_orgs if v in st.session_state.options_org]
#st.session_state.options_org = st.session_state.options_org.append(sel_orgs)
#st.write(st.session_state.options_org)
#st.write(sel_orgs)
if not set(sel_orgs).isdisjoint(st.session_state.options_org): # sel_orgs has same entries as options_org
selected = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.options_org, accept_new_options=True, default = sel_orgs)# placeholder= str(val),
#st.write(selected)#sel_orgs
for i in selected:
if i not in sel_orgs:
sel_orgs.append(selected)
else:
selected = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.options_org, accept_new_options=True)# placeholder= str(val),
#st.warning(str([i for i in sel_orgs if i not in st.session_state.options_org]) +" not found. Please search or add the correct organization via the drop down menu.")
if val != None:
st.warning(str(val) +" not found. Please search or add the correct organization via the drop down menu.")
for i in selected:
if i not in sel_orgs:
sel_orgs.append(selected)
# if selected not in sel_orgs:
# sel_orgs.append(selected)
#st.write(sel_orgs)
#st.write(selected)
# if selected == None and type(val) == list:
# st.warning(str([i for i in val if i not in st.session_state.options_org]) +" not found. Please search or add the correct organization via the drop down menu.")
# elif selected == None and type(val) != list:
# st.warning(str(val) +" not found. Please search or add the correct organization via the drop down menu.")
if selected:
st.session_state.input_json[key] = selected
##Alex
elif key == "voc4cat:CatalysisResearchField":
#st.markdown(f":small[[{key}]({st.session_state.iri_json[key]})]")
res_list = list(kg_query(onto_world, "", 5)["resField"])
#col4minia, col4minib = st.columns([2,2])
# with col4minia:
if "Res_options" not in st.session_state:
st.session_state.Res_options = res_list
if type(val) == list:
sel_res = [i for i in val if i in res_list]
for res in sel_res:
if res not in st.session_state.Res_options:
st.session_state.Res_options.append(res)
elif val in res_list:
sel_res = [val]
if val not in st.session_state.Res_options:
st.session_state.Res_options.append(val)
else:
sel_res = []
#sel_res = [v for v in sel_res if v in st.session_state.Res_options]
if not set(sel_res).isdisjoint(st.session_state.Res_options):
selected_res = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.Res_options, accept_new_options=True, default = sel_res)# placeholder= str(val),
for i in selected_res:
if i not in sel_res:
sel_res.append(selected_res)
else:
selected_res = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.Res_options, accept_new_options=True)# placeholder= str(val),
if val != None:
st.warning(str(val) +" not found. Please search or add the correct organization via the drop down menu.")
for i in selected_res:
if i not in sel_res:
sel_res.append(selected_res)
if selected_res:
st.session_state.input_json[key] = selected_res
#ALEX
elif key == "voc4cat:ReactionName":
#st.markdown(f":small[[{key}]({st.session_state.iri_json[key]})]")
rnam_list = list(kg_query(onto_world, "", 6)["reacName"])
#col4minia, col4minib = st.columns([2,2])
# with col4minia:
if "rnam_options" not in st.session_state:
st.session_state.rnam_options = rnam_list
if type(val) == list:
sel_nam = [i for i in val if i in rnam_list]
for res in sel_nam:
if res not in st.session_state.rnam_options:
st.session_state.rnam_options.append(res)
elif val in rnam_list:
sel_nam = [val]
if val not in st.session_state.rnam_options:
st.session_state.rnam_options.append(val)
else:
sel_nam = []
#sel_res = [v for v in sel_res if v in st.session_state.Res_options]
if not set(sel_nam).isdisjoint(st.session_state.rnam_options):
selected_nam = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.rnam_options, accept_new_options=True, default = sel_nam)# placeholder= str(val),
for i in selected_nam:
if i not in sel_nam:
sel_nam.append(selected_nam)
else:
selected_nam = st.multiselect(f":small[[{key}]({st.session_state.iri_json[key]})]", st.session_state.rnam_options, accept_new_options=True)# placeholder= str(val),
if val != None:
st.warning(str(val) +" not found. Please search or add the correct organization via the drop down menu.")
for i in selected_nam:
if i not in sel_nam:
sel_nam.append(selected_nam)
if selected_nam:
st.session_state.input_json[key] = selected_nam
###############
else:
st.session_state.input_json[key] = st.text_input(f"[{key}]({st.session_state.iri_json[key]})",placeholder=str(val))
if st.session_state.input_json[key]:
st.session_state.result_json[key] = st.session_state.input_json[key]
mlist = metadata_validation()
if len(mlist) == 0:
st.session_state.KGdataReady = True
#search_str_input = st.text_input("", placeholder = "Search term", label_visibility = "collapsed", icon = "🔍")
added_dict = metadata_validation_userInput()
#for key, val in st.session_state.input_json.items():
# if val != None:
# st.session_state.result_json[key] = val
#metadata_validation_userInput()
#with col4ba:
st.write("Metadata to be added:")
st.write(st.session_state.result_json)
#st.write(st.session_state.input_json)
#st.write(added_dict)
# if st.button("Validate Metadata"):
# #added_dict = metadata_validation_userInput()#metadata_validation_userInput()
# mlist = metadata_validation()
# #st.write(mlist)
# if len(mlist) == 0:
# st.session_state.KGdataReady = True
# #st.success("No Entries missing. You can add the metadata to the knowledge graph.")
# if st.button("Add to local Knowledge Graph"):
# #print("\n\n\n adding to KG\n\n\n")
# if st.session_state.KGdataReady == True:
# #print("\n\n\n adding to KG\n\n\n")
# #with onto:
# onto = dict2kg(onto, st.session_state.result_json)
# with onto:
# sync_reasoner(infer_property_values = True)
# onto.save(file="./ontologies/KnowledgeGraph_inferred.owl", format="rdfxml")
# st.success("Metadata added to the knowledge graph!")
#st.write(st.session_state.result_json)
with col5:
onto_world.close()
onto_world = owlready2.World()
onto = onto_world.get_ontology(output_path).load()
onto.name = "onto"
st.header(":green[Knowledge Graph Query]", divider="green")
st.text("Query the local knowledge graph: Select a query type and enter a search term.")
choiceList = ["People with favorite reaction","People from organization", "People with interest in catalysis domain", "People with name", "List all organizations in KG", "List all research fields in the KG", "List all reactions in the KG"]#, "People with same favourite reaction"]
choice = st.selectbox("Select the query you want to perform:",
choiceList,
index = None,
placeholder = "Select a query"
)
#st.write("You picked:", choiceList.index(choice))
if choice and choiceList.index(choice) in [0,1,2,3,7]: # 4 = list of all orgs
search_str_input = st.text_input("", placeholder = "Search term", label_visibility = "collapsed", icon = "🔍")
st.text("Tip: Click on the top right of the table for fullscreen view.")
if search_str_input:
df = kg_query(onto_world, search_str_input, choiceList.index(choice))
st.dataframe(df)
elif choice and choiceList.index(choice) in [4,5,6]:
st.text("Tip: Click on the top right of the table for fullscreen view.")
df = kg_query(onto_world, "", choiceList.index(choice))
st.dataframe(df)
# choices = st.multiselect(
# "Select one or more options:",
# ["Option A", "Option B", "Option C"]
# )
# st.write("You picked:", choices)
# if st.button("Process2"):
# if user_input.strip():
# result = call_ollama(user_input)
# st.success("Here’s the result:")
# st.write(result)
# else:
# st.warning("Please enter some text first!")
# choices = st.multiselect(
# "Select one or more options:",
# ["Option A", "Option B", "Option C"]
# )
# st.write("You picked:", choices)
# option = st.selectbox(
# "Choose a processing mode:",
# ["Simple", "Advanced", "Experimental"]
# )
# st.write(f"You selected: **{option}**")
# if "submitted" not in st.session_state:
# st.session_state.submitted = False
# def submit():
# st.session_state.submitted = True
# st.session_state.saved_text = st.session_state.user_input
# if not st.session_state.submitted:
# st.text_input("Enter something:", key="user_input", on_change=submit)
# else:
# st.success(f"You entered: {st.session_state.saved_text}")
##################### Playground #####################
# col4aa, col4ab = st.columns([1,2])
# with col4aa:
# if "options" not in st.session_state:
# st.session_state.options = ["Option A", "Option B", "Option C"]
# selected = st.multiselect("Select options:", st.session_state.options, label_visibility="collapsed")
# with col4ab:
# col4aba, col4abb = st.columns([3,1])
# with col4aba:
# new_option = st.text_input("Search", "Add own", label_visibility="collapsed")
# with col4abb:
# if st.button("Add"):
# if new_option and new_option not in st.session_state.options:
# st.session_state.options.append(new_option)
# st.session_state.added = new_option
# else:
# st.warning("Already exists or empty.")
# if "added" in st.session_state:
# selected.append(st.session_state.added)
# st.write("Current selection:", selected)
# #################################
# #
# user_input2 = st.text_input("You entered:", "")
# result2_dict = {"input_length": len(user_input2),
# "uppercase": user_input2.upper(),
# "contains_hello": "hello" in user_input2.lower()
# }
# st.write(result2_dict)
# col4a, col4b = st.columns([1,1])
# with col4a:
# json_textblock = st.code(json.dumps(st.session_state.result_json, indent=4), language="json")
# #st.write(result_json)
# with col4b:
# choices1 = st.multiselect(
# "Organizations in Knowledge Graph:",
# ["Option A1", "Option B", "Option C"]
# )
# if st.button("Add to Knowledge Graph"):
# if result_json["foaf:name"] is None:
# st.warning("Mandatory entry missing: Please provide a name:")
# input_name = st.text_input("Your name:", "")
# elif result_json["foaf:Organization"] is None:
# st.warning("Mandatory entry missing: Please provide an organization:")
# input_org = st.text_input("Your organization:", "")
# elif result_json["foaf:age"] is None:
# st.warning("Mandatory entry missing: Please provide an age:")
# input_age = st.text_input("Your age:", "")
# elif result_json["voc4cat:ReactionName"] is None:
# st.warning("Optional entry missing: Please provide a favorite reaction name:")
# input_reac = st.text_input("Your favorite reaction name:", "")
# elif result_json["voc4cat:CatalysisResearchField"] is None:
# st.warning("Optional entry missing: Please provide a favorite catalysis research field:")
# input_research = st.text_input("Your favorite catalysis research field:", "")
# else:
# st.warning("Please process some text first!")
# result_json["foaf:name"] = input_name if input_name.strip() else result_json["foaf:name"]
# st.write(result_json)
#st.write(result_json)
# if st.session_state.result_json["foaf:name"] is None:
# st.warning("Mandatory entry missing: Please provide a name:")
# if st.session_state.input_name == None:
# st.session_state.input_name = st.text_input("Your name:", "")
# #st.session_state.input_name("Your name:", "")
# st.session_state.result_json["foaf:name"] = st.session_state.input_name if st.session_state.input_name.strip() else st.session_state.result_json["foaf:name"]
# st.write(st.session_state.result_json)
# metadata_validator()
# elif st.session_state.result_json["foaf:Organization"] is None:
# st.warning("Mandatory entry missing: Please provide an organization:")
# st.session_state.input_org = st.text_input("Your organization:", "")
# # check if input_org is not empty
# st.session_state.result_json["foaf:Organization"] = input_org if input_org.strip() else st.session_state.result_json["foaf:Organization"]
# #st.write(st.session_state.result_json)
# metadata_validator()
# elif st.session_state.result_json["foaf:age"] is None:
# st.warning("Mandatory entry missing: Please provide an age:")
# st.session_state.input_age = st.text_input("Your age:", "")
# # check if input_age is a number
# if input_age and not input_age.isdigit():
# st.warning("Please enter a valid age (a number).")
# else:
# st.session_state.result_json["foaf:age"] = input_age if input_age.strip() else st.session_state.result_json["foaf:age"]
# #st.write(st.session_state.result_json)
# metadata_validator()
# elif st.session_state.result_json["voc4cat:ReactionName"] is None:
# st.warning("Optional entry missing: Please provide a favorite reaction name:")
# st.session_state.input_reac = st.text_input("Your favorite reaction name:", "")
# # check if input_reac is not empty
# st.session_state.result_json["voc4cat:ReactionName"] = input_reac if input_reac.strip() else st.session_state.result_json["voc4cat:ReactionName"]
# #st.write(st.session_state.result_json)
# metadata_validator()
# elif st.session_state.result_json["voc4cat:CatalysisResearchField"] is None:
# st.warning("Optional entry missing: Please provide a favorite catalysis research field:")
# st.session_state.input_research = st.text_input("Your favorite catalysis research field:", "")
# st.session_state.result_json["voc4cat:CatalysisResearchField"] = input_research if input_research.strip() else st.session_state.result_json["voc4cat:ReactionName"]
# #st.write(st.session_state.result_json)
# metadata_validator()
# if st.button("KG Query"):
# #df = pd.DataFrame({"x": [1,2,3], "y": [2,4,6]})
# #st.dataframe(df)
# # with open(json_name, 'r') as f:
# # #data = json.load(f)
# # json_data = json.load(f)
# #for data in json_data:
# dict2kg(onto,st.session_state.result_json)
# with onto:
# sync_reasoner()
# onto.save(file="./ontologies/KnowledgeGraph_inferred.owl", format="rdfxml")
# search_str_list = ["Maillard","Berlin","heterogen","Ma"]
# st.write(search_str_list)
# for i in [0, 1, 2, 3]:
# #print("-----")
# df = kg_query(onto_world, search_str_list[i], i)
# st.dataframe(df)
# #print("-----")
# # --- Initialize options lists in session_state ---
# if "org_options" not in st.session_state:
# st.session_state.org_options = ["TU Dortmund University", "RWTH Aachen", "LMU Munich"]
# if "dept_options" not in st.session_state:
# st.session_state.dept_options = ["Informatics", "Mechanical Engineering", "Physics"]
# # --- Define current defaults (for demonstration) ---
# sel_orgs = ["TU Dortmund University"]
# sel_depts = ["Informatics"]
# # --- Ensure defaults are valid (avoid StreamlitAPIException) ---
# sel_orgs = [v for v in sel_orgs if v in st.session_state.org_options]
# sel_depts = [v for v in sel_depts if v in st.session_state.dept_options]
# # --- Dropdown 1: Organizations ---
# selected_orgs = st.multiselect(
# "Select organization(s)",
# st.session_state.org_options,
# accept_new_options=True,
# default=sel_orgs,
# key="org_multiselect"
# )
# # --- Dropdown 2: Departments ---
# selected_depts = st.multiselect(
# "Select department(s)",
# st.session_state.dept_options,
# accept_new_options=True,
# default=sel_depts,
# key="dept_multiselect"
# )
# # --- Capture new custom entries and update options ---
# for new_org in selected_orgs:
# if new_org not in st.session_state.org_options:
# st.session_state.org_options.append(new_org)
# for new_dept in selected_depts:
# if new_dept not in st.session_state.dept_options:
# st.session_state.dept_options.append(new_dept)