wt123 commited on
Commit
035bb4d
1 Parent(s): 93521ff
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
 
4
  openai.api_key = "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"
5
 
6
- def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):
7
  response = openai.ChatCompletion.create(
8
  model=model,
9
  messages=messages,
@@ -12,11 +12,16 @@ def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0)
12
  return response.choices[0].message["content"]
13
 
14
  def get_response(text):
15
- messages = [
16
- {'role':'system', 'content':'You are a paper abstract information extractor, \
17
- the user inputs a paper abstract, and you are responsible for extracting information. \
18
  The extracted information should write in the form of: What state of the cancer (this state is usually a mutation in a driver gene) is dependent on which genes or pathways. \
19
- Do not show other information. When there is no such information (ie. cancer is not dependent on any gene or pathway from the abstract), just return "No dependency"'},
 
 
 
 
 
20
  {'role':'user', 'content':'Abstract: In non–small cell lung cancer (NSCLC), \
21
  concurrent mutations in the oncogene KRAS and the tumor suppressor STK11 encoding the kinase LKB1 result in aggressive tumors \
22
  prone to metastasis but with liabilities arising from reprogrammed metabolism. \
@@ -27,8 +32,9 @@ def get_response(text):
27
  another nitrogen-related metabolic pathway, in both mouse and human KL mutant tumors. KL cells contain high levels of HBP metabolites, \
28
  higher flux through the HBP pathway and elevated dependence on the HBP enzyme Glutamine-Fructose-6-Phosphate Transaminase 2 (GFPT2). \
29
  GFPT2 inhibition selectively reduced KL tumor cell growth in culture, xenografts and genetically-modified mice. \
30
- Our results define a new metabolic vulnerability in KL tumors and provide a rationale for targeting GFPT2 in this aggressive NSCLC subtype.'},
31
- {'role':'assistant', 'content':'KRAS/LKB1 co-mutant non–small cell lung cancer is dependent on Hexosamine biosynthesis pathway (HBP) and GFPT2.'},
 
32
  {'role':'user', 'content':'Abstract: Background: Thymidylate synthase (TYMS) is a successful chemotherapeutic target for anticancer therapy. \
33
  Numerous TYMS inhibitors have been developed and used for treating gastrointestinal cancer now, but they have limited clinical benefits due to \
34
  the prevalent unresponsiveness and toxicity. It is urgent to identify a predictive biomarker to guide the precise clinical use of TYMS inhibitors. \
@@ -42,7 +48,7 @@ def get_response(text):
42
  TYMS mRNA levels than those of progressive diseases. NIPBL inactivation decreases the therapeutic responses of \
43
  gastrointestinal cancer to RTX through blocking MYC. Interpretation: Our study unveils a mechanism of how TYMS is \
44
  transcriptionally regulated by MYC, and provides rationales for the precise use of TYMS inhibitors in the clinic.'},
45
- {'role':'assistant', 'content':'Gastrointestinal cancer with up-regulated MYC is dependent on TYMS.'},
46
  {'role':'user', 'content':'Abstract: Studies have characterized the immune escape landscape across primary tumors. \
47
  However, whether late-stage metastatic tumors present differences in genetic immune escape (GIE) prevalence and dynamics remains unclear. \
48
  We performed a pan-cancer characterization of GIE prevalence across six immune escape pathways in 6,319 uniformly processed tumor samples. \
@@ -52,11 +58,11 @@ def get_response(text):
52
  in tumor evolution and focal loss of heterozygosity of HLA-I tends to eliminate the HLA allele, presenting the largest neoepitope repertoire. \
53
  Finally, high mutational burden tumors showed a tendency toward focal loss of heterozygosity of HLA-I as the immune evasion mechanism, \
54
  whereas, in hypermutated tumors, other immune evasion strategies prevail.'},
55
- {'role':'assistant', 'content':'No dependency'}
56
  ]
57
  messages.append({'role':'user', 'content':f"Abstract: {text}"})
58
  response = get_completion_from_messages(messages, temperature=0)
59
- return response
60
 
61
  exp = [[
62
  "Background: Triple-negative breast cancer (TNBC) is an aggressive subtype of breast cancer, \
@@ -92,7 +98,10 @@ def gradio():
92
 
93
  output_text = gr.outputs.Textbox(label="Extracted information")
94
 
95
- interface = gr.Interface(fn=get_response, inputs=[input_text], outputs=output_text, examples=exp,
 
 
 
96
  article="Example abstract from https://doi.org/10.21203/rs.3.rs-1547583/v1 and https://doi.org/10.1038/s41590-022-01129-x")
97
  interface.launch()
98
 
 
3
 
4
  openai.api_key = "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"
5
 
6
+ def get_completion_from_messages(messages, model="gpt-3.5-turbo-0613", temperature=0):
7
  response = openai.ChatCompletion.create(
8
  model=model,
9
  messages=messages,
 
12
  return response.choices[0].message["content"]
13
 
14
  def get_response(text):
15
+ messages = [
16
+ {'role':'system', 'content':'You are a paper abstract information extractor, Your task is to perform the following actions:\
17
+ 1. the user inputs a paper abstract, and you are responsible for extracting information. \
18
  The extracted information should write in the form of: What state of the cancer (this state is usually a mutation in a driver gene) is dependent on which genes or pathways. \
19
+ Do not show other information. When there is no such information (ie. cancer is not dependent on any gene or pathway from the \
20
+ abstract), just return "No dependency". \
21
+ 2. Format output as a json object that contains the following keys: cancer, state, gene/pathway. \
22
+ Use the following format: \
23
+ Extracted information: <Extracted information> \
24
+ Output JSON: <json with cancer, state and gene/pathway>. When there is no dependency, do not output JSON'},
25
  {'role':'user', 'content':'Abstract: In non–small cell lung cancer (NSCLC), \
26
  concurrent mutations in the oncogene KRAS and the tumor suppressor STK11 encoding the kinase LKB1 result in aggressive tumors \
27
  prone to metastasis but with liabilities arising from reprogrammed metabolism. \
 
32
  another nitrogen-related metabolic pathway, in both mouse and human KL mutant tumors. KL cells contain high levels of HBP metabolites, \
33
  higher flux through the HBP pathway and elevated dependence on the HBP enzyme Glutamine-Fructose-6-Phosphate Transaminase 2 (GFPT2). \
34
  GFPT2 inhibition selectively reduced KL tumor cell growth in culture, xenografts and genetically-modified mice. \
35
+ Our results define a new metabolic vulnerability in KL tumors and provide a rationale for targeting GFPT2 in this aggressive NSCLC subtype.'},
36
+ {'role':'assistant', 'content':'Extracted information: KRAS/LKB1 co-mutant non–small cell lung cancer is dependent on Hexosamine \
37
+ biosynthesis pathway (HBP) and GFPT2. Output JSON: {"cancer":"non–small cell lung cancer","state":"KRAS/LKB1 co-mutant","gene/pathway":"Hexosamine biosynthesis pathway (HBP) and GFPT2"}'},
38
  {'role':'user', 'content':'Abstract: Background: Thymidylate synthase (TYMS) is a successful chemotherapeutic target for anticancer therapy. \
39
  Numerous TYMS inhibitors have been developed and used for treating gastrointestinal cancer now, but they have limited clinical benefits due to \
40
  the prevalent unresponsiveness and toxicity. It is urgent to identify a predictive biomarker to guide the precise clinical use of TYMS inhibitors. \
 
48
  TYMS mRNA levels than those of progressive diseases. NIPBL inactivation decreases the therapeutic responses of \
49
  gastrointestinal cancer to RTX through blocking MYC. Interpretation: Our study unveils a mechanism of how TYMS is \
50
  transcriptionally regulated by MYC, and provides rationales for the precise use of TYMS inhibitors in the clinic.'},
51
+ {'role':'assistant', 'content':'Extracted information: Gastrointestinal cancer with up-regulated MYC is dependent on TYMS. Output JSON: {"cancer":"Gastrointestinal cancer","state":"up-regulated MYC","gene/pathway":"TYMS"}'},
52
  {'role':'user', 'content':'Abstract: Studies have characterized the immune escape landscape across primary tumors. \
53
  However, whether late-stage metastatic tumors present differences in genetic immune escape (GIE) prevalence and dynamics remains unclear. \
54
  We performed a pan-cancer characterization of GIE prevalence across six immune escape pathways in 6,319 uniformly processed tumor samples. \
 
58
  in tumor evolution and focal loss of heterozygosity of HLA-I tends to eliminate the HLA allele, presenting the largest neoepitope repertoire. \
59
  Finally, high mutational burden tumors showed a tendency toward focal loss of heterozygosity of HLA-I as the immune evasion mechanism, \
60
  whereas, in hypermutated tumors, other immune evasion strategies prevail.'},
61
+ {'role':'assistant', 'content':'Extracted information: No dependency}'}
62
  ]
63
  messages.append({'role':'user', 'content':f"Abstract: {text}"})
64
  response = get_completion_from_messages(messages, temperature=0)
65
+ return response.split("Output JSON: ")[0], json.loads(response.split("Output JSON: ")[1])
66
 
67
  exp = [[
68
  "Background: Triple-negative breast cancer (TNBC) is an aggressive subtype of breast cancer, \
 
98
 
99
  output_text = gr.outputs.Textbox(label="Extracted information")
100
 
101
+ json_output = gr.JSON(label = "JSON")
102
+
103
+ interface = gr.Interface(fn=get_response, inputs=[input_text], outputs=[output_text,json_output],
104
+ examples=exp,
105
  article="Example abstract from https://doi.org/10.21203/rs.3.rs-1547583/v1 and https://doi.org/10.1038/s41590-022-01129-x")
106
  interface.launch()
107