File size: 7,222 Bytes
be6deff
834978e
5769515
dfeeedc
be6deff
8392b33
d8a8ced
4b96e78
d8a8ced
 
6aaa0db
d8a8ced
0ecf059
b18cd84
6f9e91f
78b66c2
1ecd2bc
 
 
 
a23a68c
5a5912b
78b66c2
1ecd2bc
bb0161f
1ecd2bc
 
6aaa0db
1ecd2bc
 
4b96e78
1ecd2bc
4b96e78
1ecd2bc
 
 
 
 
624e912
36ca3a9
2b0664d
c129d7d
4c644f1
 
 
 
 
 
 
 
 
 
bb0161f
 
 
 
bc0561b
 
 
 
 
 
 
 
 
 
 
 
bb0161f
 
 
7d4e93a
bb0161f
a73442f
5803605
48ed8f4
 
9b89a02
48ed8f4
d7207c4
0a96d8b
834978e
78b66c2
2776a50
d8a5a74
78b66c2
b855d19
245f91b
882cc77
2ae1bd5
 
e1b56c8
 
245f91b
fb3a009
5a5912b
2ae1bd5
0a96d8b
 
03301f1
 
48ed8f4
03301f1
0a96d8b
5a5912b
11c5791
 
 
 
fb3a009
6caedd6
78b66c2
8392b33
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
import gradio as gr
import subprocess
import pandas as pd
import tempfile

'''
import gradio as gr

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
'''
def greet(name1, name2):
    # Storing each input in a variable, you can process or save them as you like
    str1_openai = name1 ## openai
    str2_bioportal = "213e22ba-4c3b-402b-bd36-6e9d4e86b1b5"   #bioportal
    str3_huggingface = "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"   # huggingface
    str4_input = name2
    
    
    with open('abstractsave.txt', 'w') as f:
        f.write(str4_input)
    
    def run_command(command):
        result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

        output_string = result.stdout
        error_string = result.stderr

        return output_string, error_string

#####     output_string1, error_string1= run_command("pip install optogpt")
    output_string1, error_string1 = run_command("curl -sSL https://install.python-poetry.org | python3 -")
    output_string2, error_string2 = run_command(f"poetry run runoak set-apikey -e openai {str1_openai}")
    run_command(f"poetry run runoak set-apikey -e bioportal {str2_bioportal}")
    run_command(f"poetry run runoak set-apikey -e hfhub-key {str3_huggingface}")
#####     output = run_command(f"ontogpt extract -t gocam.GoCamAnnotations -i ./abstract.txt")
    output = run_command(f"mcodegpt extract -t cancer.CancerAnnotations -i ./abstractsave.txt")
    
    output = output[0].replace('\\n', '\n')
    
    # Find the positions of the start and end markers
    start_marker = "raw_completion_output: |-"
    end_marker = "prompt: "
    start_position = output.find(start_marker)
    end_position = output.find(end_marker)

    # Extract the text between the start and end positions
    output = output[start_position + len(start_marker):end_position].strip()


    # Splitting the data string into lines and then split each line into key-value pairs
    key_value_pairs = [line.split(": ", 1) for line in output.split("\n")[1:] if line.strip()]

    def format_identifier(identifier: str) -> str:
        # Split the string by underscores
        words = identifier.strip().split('_')

        # Capitalize each word
        capitalized_words = [word.capitalize() for word in words]

        # Join the words with spaces
        formatted_identifier = ' '.join(capitalized_words)

        return formatted_identifier

    key_value_pairs = [[format_identifier(x[0]), *x[1:]] for x in key_value_pairs]
    
    # Convert the key-value pairs into a table format (a list of lists)
    df_pred = pd.DataFrame(key_value_pairs, columns = ["Ontology Attribute", "Value"]).iloc[:19,:]
    
    html_output = df_pred.to_html()
    
    # Save the CSV data to a temporary file
    with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
        df_pred.to_csv(temp_file.name, index=False)
        csv_output = temp_file.name

    return html_output, csv_output

input_boxes = [
    gr.inputs.Textbox(label="openai api key"),
    gr.inputs.Textbox(lines=20, label="Input cancer report", placeholder='Type text here...'),
]

disclaimer = (
    "Please do not upload sensitive patient data. <br>" 
    'If you need support, please contact us at '
    '<a href="https://899f8a5b.limecube.co/" target="_blank"> limecube </a> or '
    '<a href="https://mcodegpt.org/" target="_blank"> mCodeGPT</a>. <br>'
    'HIPPA-compliant version is under development and will be online soon.'
)



iface = gr.Interface(fn=greet, 
                     inputs=input_boxes, 
                     outputs=[
                            gr.outputs.HTML(label="Output Table"), 
                            gr.outputs.File(label="Download Output as CSV")
                        ],
                     
                     examples=[                                   
        ["87uigiyyu&979890909nY9j87y8n78 (replace with your own OpenAI key)", "Patient John Smith (HSI-5421) underwent a tissue biopsy at the bladder collection site. The histopathology report confirmed the presence of cancer in the bladder. The tumor, identified as T-BC5421, measures 4 cm in its longest dimension. The cancer has been staged as T2, indicating its progression beyond the bladder wall. The cancer was asserted on January 10, 2022. The tumor marker test revealed elevated levels of urinary bladder tumor antigen (UBTA). John Smith, a Caucasian male born on April 15, 1975, is non-Hispanic and resides in zip code 90210. He is still alive, with no reported death date at this time. For any further information, please contact John Smith at [email protected] or (555) 123-4567." ],
        ["87uigiyyu&979890909nY9j87y8n78 (replace with your own OpenAI key)", "Patient CS1256, Emma Thompson, is a 42-year-old non-Hispanic white female with a biopsy specimen collected from the cervix. The pathology report indicates the presence of a tumor with an identified tumor identifier, T123456, located in the cervix. The tumor has a longest dimension of 2.3 cm. Based on the staging, the cancer is classified as Stage IA. The cancer was asserted on March 10, 2020. The tumor marker test result for CA-125 is 32 U/mL. Further evaluation and treatment options will be discussed with the patient. For any inquiries or updates, please contact Emma Thompson at [email protected] or (555) 123-4567."],
    ["87uigiyyu&979890909nY9j87y8n78  (replace with your own OpenAI key)", "This cancer report is for patient Emily Johnson (HS123456), a 43-year-old white female residing in zip code 12345. The patient underwent a tissue biopsy at Memorial Hospital to collect the human specimen. The tumor identified as T12345 is located in the femur, with a size of 10 cm in its longest dimension. The cancer stage is classified as Stage III, and the cancer was asserted on June 5, 2021. The body site affected by the cancer is the bones and joints. The disease status evidence is based on an MRI scan. Additionally, the tumor marker test revealed elevated levels of alkaline phosphatase. As of now, the patient is still alive, and no death date has been recorded. For further communication, Emily Johnson can be reached at 555-1234 or [email protected]."],
["87uigiyyu&979890909nY9j87y8n78 (replace with your own OpenAI key)", "Patient HS-56789, Samuel Thompson, underwent a tissue biopsy at the National Cancer Institute for further investigation. The biopsy revealed the presence of cancer in Samuel's abdominal region. The tumor, identified as T-98765, measures 12 cm in its longest dimension. Based on the radiology report, the cancer has progressed to Stage III. The cancer, located in the retroperitoneum, was asserted on September 5, 2021. Further testing showed an elevated level of the tumor marker CA-125. Samuel Thompson's demographic information includes his birth date on June 10, 1975, and his contact information as [email protected], and +1 (555) 123-4567. He identifies as a Caucasian male of non-Hispanic ethnicity, residing in zip code 12345. As of now, there is no record of his death."]],
                    description=disclaimer)

iface.launch()