Roland Ding commited on
Commit
858a4f7
·
1 Parent(s): ca2e8a8

6.5.16.44 updated the ui and added backend loading.

Browse files
Files changed (6) hide show
  1. app.py +6 -5
  2. application.py +5 -7
  3. cloud_storage.py +2 -2
  4. features.py +19 -24
  5. ui_device.py +1 -1
  6. ui_list.py +0 -57
app.py CHANGED
@@ -9,19 +9,20 @@ import gradio as gr
9
 
10
  from cloud_db import *
11
  from supplier import *
12
- from ui_device import *
13
- from ui_equivalent import *
14
- from ui_study import *
15
  from utility import *
16
 
 
 
 
 
17
  examples = []
18
  # app_theme = gr.themes.Base(neutral_hue="blue")
19
 
20
  demo = gr.TabbedInterface(
21
  # [device_page,study_page,equivalent_page],
22
  # ["Device","Clinical Study Report","Equivalent Comparators"],
23
- [study_page],
24
- ["Clinical Study"],
25
  theme = gr.themes.Soft(primary_hue="sky",secondary_hue="orange"),
26
  css = "footer {visibility: hidden}",
27
  title="AMRA AI Medi Reader")
 
9
 
10
  from cloud_db import *
11
  from supplier import *
 
 
 
12
  from utility import *
13
 
14
+ from ui_study import *
15
+ from ui_studies import *
16
+
17
+
18
  examples = []
19
  # app_theme = gr.themes.Base(neutral_hue="blue")
20
 
21
  demo = gr.TabbedInterface(
22
  # [device_page,study_page,equivalent_page],
23
  # ["Device","Clinical Study Report","Equivalent Comparators"],
24
+ [study_page,studies_page],
25
+ ["Clinical Study","Studies"],
26
  theme = gr.themes.Soft(primary_hue="sky",secondary_hue="orange"),
27
  css = "footer {visibility: hidden}",
28
  title="AMRA AI Medi Reader")
application.py CHANGED
@@ -65,22 +65,19 @@ data_structure = {
65
  "fields":[
66
  "domain",
67
  "name",
68
- "s3_path",
69
- "vector",
70
- "meta",
71
- "content"
72
  ]
73
  },
74
  "outputs":{
75
  "key":[
76
  "domain",
77
- "article",
78
- "outcomes"
79
  ],
80
  "fields":[
81
  "domain",
82
  "article",
83
- "output"
84
  ]
85
  }
86
  }
@@ -90,6 +87,7 @@ application default data
90
  '''
91
  app_data = {
92
  "current_article":{},
 
93
  "terms":[],
94
  "prompts":[],
95
  "outputs":[]
 
65
  "fields":[
66
  "domain",
67
  "name",
68
+ "content",
69
+ "upload_time"
 
 
70
  ]
71
  },
72
  "outputs":{
73
  "key":[
74
  "domain",
75
+ "article"
 
76
  ],
77
  "fields":[
78
  "domain",
79
  "article",
80
+ "outcomes"
81
  ]
82
  }
83
  }
 
87
  '''
88
  app_data = {
89
  "current_article":{},
90
+ "articles":[],
91
  "terms":[],
92
  "prompts":[],
93
  "outputs":[]
cloud_storage.py CHANGED
@@ -27,11 +27,11 @@ def upload_file(path, bucket, object_name=None):
27
 
28
  try:
29
 
30
- s3.upload_file(path, bucket, object_name)
31
  except Exception as e:
32
  print(e)
33
  return False
34
- return
35
 
36
  def upload_fileobj(file_obj, bucket, object_name=None):
37
  '''
 
27
 
28
  try:
29
 
30
+ res = s3.upload_file(path, bucket, object_name)
31
  except Exception as e:
32
  print(e)
33
  return False
34
+ return res
35
 
36
  def upload_fileobj(file_obj, bucket, object_name=None):
37
  '''
features.py CHANGED
@@ -39,19 +39,15 @@ def process_study(
39
  app_data["current_article"] = article
40
  selected_prompts = select_prompts(article["content"],terms=app_data["terms"],prompts=app_data["prompts"])
41
 
 
42
  output = {
43
  "domain":article["domain"],
44
  "article":article["name"],
45
- "outcomes":defaultdict(str)
46
  }
47
-
48
- res = process_prompts(article["content"],selected_prompts)
49
- output["outcomes"] = res
50
-
51
- # overview = create_overview(output["output"]["Overview"])
52
- views = create_views(res)
53
-
54
  add_output(output)
 
55
 
56
  return views
57
  # return ""
@@ -63,16 +59,17 @@ def refresh():
63
  init_app_data()
64
 
65
  article = app_data["current_article"]
66
- selected_prompts = select_prompts(article["content"],terms=app_data["terms"],prompts=app_data["prompts"])
67
-
 
 
 
 
68
  output = {
69
  "domain":article["domain"],
70
  "article":article["name"],
71
- "outcomes":defaultdict(str)
72
  }
73
-
74
- res = process_prompts(article["content"],selected_prompts)
75
- output["outcomes"] = res
76
  views = create_views(res)
77
  add_output(output)
78
 
@@ -84,11 +81,11 @@ def create_views(output):
84
  overview = [v for _,v in output.items() if v["assessment"] == "overview"][0]
85
  safety = [v for _,v in output.items() if v["assessment"] == "safety"][0]
86
  # add overview
87
- md_text += f"<details>\n<summary><h2>Overivew</h2></summary>\n\n"
88
  md_text += overview["content"] + "\n</details>\n\n"
89
 
90
  # add performance
91
- md_text += f"<details>\n<summary><h2>Performance</h2></summary>\n\n"
92
  for title,content in output.items():
93
  if content["assessment"] not in ["overview","safety"]:
94
  md_text += f"#### {content['assessment']} - {title}\n\n"
@@ -96,12 +93,11 @@ def create_views(output):
96
  md_text += "</details>\n\n"
97
 
98
  # add safety
99
- md_text += f"<details>\n<summary><h2>Safety</h2></summary>\n\n"
100
  md_text += safety["content"] + "\n\n" + "</details>\n\n"
101
 
102
  return gr.update(value=md_text)
103
 
104
-
105
  def extract_key_content(text,start,end,before = None,case_sensitive=False):
106
  '''
107
  this function extract the content between start and end
@@ -227,8 +223,7 @@ def add_article(domain,file,add_to_s3=True, add_to_local=True, file_object=True)
227
  }
228
 
229
  if add_to_s3 and file_object:
230
- s3_path = upload_fileobj(file,domain,filename)
231
- article["s3_path"] = s3_path
232
 
233
  if add_to_local:
234
  app_data["articles"].append(article)
@@ -290,8 +285,7 @@ def update_article(article,file_obj=None,update_local=True):
290
  article object
291
  '''
292
  if file_obj:
293
- s3_path = upload_fileobj(file_obj,article["domain"],article["name"])
294
- article["s3_path"] = s3_path
295
 
296
  if update_local:
297
  app_data["articles"].append(article)
@@ -315,10 +309,11 @@ def add_output(output):
315
  True if success
316
  '''
317
  res = post_item("outputs",output)
 
318
  if "Error" in res:
319
  print(res)
320
  return False
321
- return True
322
 
323
  def get_output(domain,name):
324
  res = output = get_item("outputs",{"domain":domain,"name":name})
@@ -404,7 +399,7 @@ def process_prompts(text,prompts):
404
  dict
405
  processed extraction results from openai api
406
  '''
407
- res = defaultdict(dict)
408
  for p in prompts:
409
  inst = [
410
  p["prompt"]+", ".join(p["fields"]),
 
39
  app_data["current_article"] = article
40
  selected_prompts = select_prompts(article["content"],terms=app_data["terms"],prompts=app_data["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 ""
 
59
  init_app_data()
60
 
61
  article = app_data["current_article"]
62
+ if not article:
63
+ return "No file or content provided"
64
+ selected_prompts = select_prompts(article["content"],terms=app_data["terms"],prompts=app_data["prompts"])
65
+
66
+ res = process_prompts(article["content"],selected_prompts)
67
+
68
  output = {
69
  "domain":article["domain"],
70
  "article":article["name"],
71
+ "outcomes":res
72
  }
 
 
 
73
  views = create_views(res)
74
  add_output(output)
75
 
 
81
  overview = [v for _,v in output.items() if v["assessment"] == "overview"][0]
82
  safety = [v for _,v in output.items() if v["assessment"] == "safety"][0]
83
  # add overview
84
+ md_text += f"<details><summary><b>Overivew</b></summary>\n\n"
85
  md_text += overview["content"] + "\n</details>\n\n"
86
 
87
  # add performance
88
+ md_text += f"<details><summary><b>Performance</b></summary>\n\n"
89
  for title,content in output.items():
90
  if content["assessment"] not in ["overview","safety"]:
91
  md_text += f"#### {content['assessment']} - {title}\n\n"
 
93
  md_text += "</details>\n\n"
94
 
95
  # add safety
96
+ md_text += f"<details><summary><b>Safety</b></summary>\n\n"
97
  md_text += safety["content"] + "\n\n" + "</details>\n\n"
98
 
99
  return gr.update(value=md_text)
100
 
 
101
  def extract_key_content(text,start,end,before = None,case_sensitive=False):
102
  '''
103
  this function extract the content between start and end
 
223
  }
224
 
225
  if add_to_s3 and file_object:
226
+ upload_fileobj(file,domain,filename)
 
227
 
228
  if add_to_local:
229
  app_data["articles"].append(article)
 
285
  article object
286
  '''
287
  if file_obj:
288
+ upload_fileobj(file_obj,article["domain"],article["name"])
 
289
 
290
  if update_local:
291
  app_data["articles"].append(article)
 
309
  True if success
310
  '''
311
  res = post_item("outputs",output)
312
+
313
  if "Error" in res:
314
  print(res)
315
  return False
316
+ return res
317
 
318
  def get_output(domain,name):
319
  res = output = get_item("outputs",{"domain":domain,"name":name})
 
399
  dict
400
  processed extraction results from openai api
401
  '''
402
+ res = {}
403
  for p in prompts:
404
  inst = [
405
  p["prompt"]+", ".join(p["fields"]),
ui_device.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from utility import *
4
  from application import *
5
  from features import init_app_data, add_device
6
- from ui_list import render_list
7
 
8
  def refresh_ui_device():
9
  # init_app_data()
 
3
  from utility import *
4
  from application import *
5
  from features import init_app_data, add_device
6
+ # from ui_list import render_list
7
 
8
  def refresh_ui_device():
9
  # init_app_data()
ui_list.py DELETED
@@ -1,57 +0,0 @@
1
- import gradio as gr
2
-
3
- from cloud_db import *
4
-
5
- def render_list(items,title="Item List"):
6
- with gr.Blocks() as item_list:
7
- # title of the file list
8
- gr.HTML(f"<h2>{title}</h2>")
9
-
10
- with gr.Row():
11
- with gr.Column(scale=2):
12
- with gr.Row():
13
- gr.HTML("<h3>Device</h3>")
14
- gr.HTML("<h3>Article Name</h3>")
15
- gr.HTML("<h3>Upload Time</h3>")
16
- gr.HTML("<h3>File Link</h3>")
17
- # with gr.Column():
18
- # pass
19
-
20
- gr.HTML("<hr />")
21
-
22
- for i in items:
23
- with gr.Row() as this_row:
24
- with gr.Column(scale=2):
25
- with gr.Row():
26
- gr.HTML(i["domain"])
27
- gr.HTML(i["name"])
28
- gr.HTML(i["upload_time"])
29
- if "s3_path" in i:
30
- gr.HTML(f"<a href='{i['s3_path']}' target='_blank'>link</a>")
31
- # with gr.Column():
32
- # with gr.Row():
33
- # btn_view = gr.Button("view",variant="primary")
34
- # btn_delete = gr.Button("Delete",variant="danger")
35
-
36
- gr.HTML("<hr />")
37
- # btn_delete.click(fn=delete)
38
-
39
- return item_list
40
-
41
- if __name__ == "__main__":
42
- file_list = [
43
- {
44
- "domain":"Device",
45
- "name":"Device 1",
46
- "s3_path":"https://www.google.com",
47
- "upload_time":"2021-01-01"
48
- },
49
- {
50
- "domain":"Device",
51
- "name":"Device 2",
52
- "s3_path":"https://www.google.com",
53
- "upload_time":"2021-01-01"
54
- },
55
- ]
56
- interface = render_file_list(file_list)
57
- interface.launch()