Spaces:
Runtime error
Runtime error
Roland Ding
commited on
Commit
•
844a2ba
1
Parent(s):
c9ba1c0
7.7.18.49 updated the application.py and features.py for including existing table extraction and remove anything from article after discussion session. updated the interface to allow unequal heights of components and added original tables in study page.
Browse files- application.py +9 -0
- features.py +9 -2
- ui_study.py +3 -1
- utility.py +27 -0
application.py
CHANGED
@@ -82,6 +82,15 @@ data_structure = {
|
|
82 |
}
|
83 |
}
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
'''
|
86 |
application default data
|
87 |
'''
|
|
|
82 |
}
|
83 |
}
|
84 |
|
85 |
+
source_format = "<column 1 field>\n<value 1>\n<value 2>...<value n>\n<column 2 field>\n<value 1>\n<value 2>...<value n>\n...<column n field>\n<value 1>\n<value 2>...<value n>\n"
|
86 |
+
|
87 |
+
tables_inst=[
|
88 |
+
f"extract tables from the system text. the tables are mostly in the following format: {source_format}",
|
89 |
+
f"reformat the returned tables into a markdown table syntax.",
|
90 |
+
f"if applicable, remove the standard deviation after the mean and round all the numbers to one decimal places.",
|
91 |
+
f"include all table titles."
|
92 |
+
]
|
93 |
+
|
94 |
'''
|
95 |
application default data
|
96 |
'''
|
features.py
CHANGED
@@ -35,21 +35,28 @@ def process_study(
|
|
35 |
article = add_article(device,study_content,file_object=False)
|
36 |
else:
|
37 |
return "No file or content provided","No file or content provided","No file or content provided"
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
app_data["current_article"] = article
|
40 |
-
selected_prompts = select_prompts(
|
41 |
|
42 |
res = process_prompts(article["content"],selected_prompts)
|
43 |
output = {
|
44 |
"domain":article["domain"],
|
45 |
"article":article["name"],
|
|
|
46 |
"outcomes":res
|
47 |
}
|
48 |
|
49 |
add_output(output)
|
50 |
views = create_views(res)
|
51 |
|
52 |
-
return views
|
53 |
# return ""
|
54 |
|
55 |
def refresh():
|
|
|
35 |
article = add_article(device,study_content,file_object=False)
|
36 |
else:
|
37 |
return "No file or content provided","No file or content provided","No file or content provided"
|
38 |
+
|
39 |
+
end_index = article["content"].lower().index("discussion")
|
40 |
+
key_content = article["content"][:end_index] if end_index > 0 else article["content"]
|
41 |
+
|
42 |
+
tables = send_inst(create_inst(key_content,tables_inst))
|
43 |
+
key_content += tables
|
44 |
|
45 |
app_data["current_article"] = article
|
46 |
+
selected_prompts = select_prompts(key_content,terms=app_data["terms"],prompts=app_data["prompts"])
|
47 |
|
48 |
res = process_prompts(article["content"],selected_prompts)
|
49 |
output = {
|
50 |
"domain":article["domain"],
|
51 |
"article":article["name"],
|
52 |
+
"tables":tables,
|
53 |
"outcomes":res
|
54 |
}
|
55 |
|
56 |
add_output(output)
|
57 |
views = create_views(res)
|
58 |
|
59 |
+
return views, tables
|
60 |
# return ""
|
61 |
|
62 |
def refresh():
|
ui_study.py
CHANGED
@@ -15,7 +15,7 @@ def reset():
|
|
15 |
)
|
16 |
|
17 |
with gr.Blocks() as study_page:
|
18 |
-
with gr.Row():
|
19 |
with gr.Column():
|
20 |
gr.Markdown("## Studies")
|
21 |
gr.HTML("<hr>")
|
@@ -23,6 +23,7 @@ with gr.Blocks() as study_page:
|
|
23 |
upload_study = gr.File(label="Upload a clinical study report",type="file")
|
24 |
|
25 |
input_study = gr.TextArea(label="Or paste a clinical study report content",placeholder="Paste content here...",lines=5)
|
|
|
26 |
|
27 |
with gr.Row():
|
28 |
btn_reset = gr.Button(value="Reset",variant="stop")
|
@@ -51,6 +52,7 @@ with gr.Blocks() as study_page:
|
|
51 |
],
|
52 |
outputs=[
|
53 |
views,
|
|
|
54 |
],
|
55 |
)
|
56 |
|
|
|
15 |
)
|
16 |
|
17 |
with gr.Blocks() as study_page:
|
18 |
+
with gr.Row(equal_height=False):
|
19 |
with gr.Column():
|
20 |
gr.Markdown("## Studies")
|
21 |
gr.HTML("<hr>")
|
|
|
23 |
upload_study = gr.File(label="Upload a clinical study report",type="file")
|
24 |
|
25 |
input_study = gr.TextArea(label="Or paste a clinical study report content",placeholder="Paste content here...",lines=5)
|
26 |
+
tables = gr.Markdown("")
|
27 |
|
28 |
with gr.Row():
|
29 |
btn_reset = gr.Button(value="Reset",variant="stop")
|
|
|
52 |
],
|
53 |
outputs=[
|
54 |
views,
|
55 |
+
tables
|
56 |
],
|
57 |
)
|
58 |
|
utility.py
CHANGED
@@ -194,3 +194,30 @@ following functions are used for business logic. (to be moved to business logic
|
|
194 |
def est_cost(n_tokens,rate):
|
195 |
return round(rate*n_tokens/1000,4)
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
def est_cost(n_tokens,rate):
|
195 |
return round(rate*n_tokens/1000,4)
|
196 |
|
197 |
+
|
198 |
+
def replace_symbols(s):
|
199 |
+
'''
|
200 |
+
this function replace symbols in the string to comply with file names
|
201 |
+
|
202 |
+
Parameters
|
203 |
+
----------
|
204 |
+
s : str
|
205 |
+
string to be replaced
|
206 |
+
|
207 |
+
Returns
|
208 |
+
-------
|
209 |
+
str
|
210 |
+
replaced string
|
211 |
+
'''
|
212 |
+
s = s.replace(" ","_")
|
213 |
+
s = s.replace(",","")
|
214 |
+
s = s.replace(".","")
|
215 |
+
s = s.replace("-","_")
|
216 |
+
s = s.replace("(","")
|
217 |
+
s = s.replace(")","")
|
218 |
+
s = s.replace("/","_")
|
219 |
+
s = s.replace(":","")
|
220 |
+
s = s.replace(";","")
|
221 |
+
s = s.replace("'","")
|
222 |
+
s = s.replace('"',"")
|
223 |
+
return remove_symbols(s)
|