happyGPT commited on
Commit
8e003ee
·
verified ·
1 Parent(s): 8599fb4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +138 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from openai import OpenAI
4
+
5
+
6
+ def demo(project_TCGA, output_language="Chinese"):
7
+ name_English, name_Chinese = project_name_TCGA[project_TCGA]
8
+ output1, output2 = None, None
9
+
10
+ if output_language == "Chinese":
11
+ output1 = f"✍️ 简称:{project_TCGA}\n❤️ 中文全称:{name_Chinese}\n💛 英文全称:{name_English}"
12
+ system_instruction = f"您是系统生物学、流行病学、癌症研究和精准医学领域的专家,对{name_Chinese}有着深刻的洞察。"
13
+ prompt_template = f"""
14
+ 您的任务是深入分析{name_Chinese}这一复杂疾病,并深入探索其发病和进展中涉及的关键的分子机制与信号通路。让我们一步一步地思考。
15
+ """.strip()
16
+ else:
17
+ output1 = f"✍️ Abbreviation: {project_TCGA}\n❤️ Full name in Chinese: {name_Chinese}\n💛 Full Name in English: {name_English}"
18
+ system_instruction = f"You are an expert in the fields of systems biology, epidemiology, cancer research, and precision medicine, with deep insights into {name_English}."
19
+ prompt_template = f"""
20
+ Your task is to analyze in depth the complex disease of {name_English} and to explore in depth the key molecular mechanisms and signaling pathways involved in its initiation and progression. Let's think step by step.
21
+ """.strip()
22
+
23
+ try:
24
+ # 要实例化一个 OpenAI 对象,你需要设置 OpenAI API Key、Base URL、最大重试次数以及超时限制时间。
25
+ client = OpenAI(
26
+ api_key=os.environ["OPENAI_API_KEY"],
27
+ base_url=os.environ["API_BASE"],
28
+ max_retries=3,
29
+ timeout=60,
30
+ )
31
+ # 调用 client.chat.completions.create,设置关键参数。
32
+ chat_completion = client.chat.completions.create(
33
+ model="gpt-4o-mini-2024-07-18",
34
+ messages=[
35
+ {"role": "system", "content": system_instruction},
36
+ {"role": "user", "content": prompt_template},
37
+ ],
38
+ n=1,
39
+ temperature=0.30,
40
+ seed=42,
41
+ max_tokens=2048,
42
+ logprobs=True,
43
+ top_logprobs=3,
44
+ presence_penalty=0,
45
+ frequency_penalty=0,
46
+ )
47
+ resp_text = chat_completion.choices[0].message.content.strip()
48
+
49
+ # 在普通文本框不能用 "**" 渲染加粗,Markdown 才可以。因此,将输入字符串中所有的 "**" 替换为 ""。
50
+ if "**" in resp_text:
51
+ output2 = resp_text.replace("**", "")
52
+
53
+ except Exception as e:
54
+ print(str(e), "Response Error")
55
+ return str(e), "Response Error"
56
+
57
+ return output1, output2
58
+
59
+
60
+ project_name_TCGA = {
61
+ "TCGA-ACC": ["adrenocortical carcinoma", "肾上腺皮质癌"],
62
+ "TCGA-BLCA": ["bladder urothelial carcinoma", "膀胱尿路上皮癌"],
63
+ "TCGA-BRCA": ["breast invasive carcinoma", "浸润性乳腺癌"],
64
+ "TCGA-CESC": [
65
+ "cervical squamous cell carcinoma and endocervical adenocarcinoma",
66
+ "宫颈鳞状细胞癌与宫颈内膜腺癌",
67
+ ],
68
+ "TCGA-CHOL": ["cholangiocarcinoma", "胆管癌"],
69
+ "TCGA-COAD": ["colon adenocarcinoma", "结肠腺癌"],
70
+ "TCGA-DLBC": [
71
+ "lymphoid neoplasm diffuse large B-cell lymphoma",
72
+ "弥漫性大 B 细胞淋巴瘤",
73
+ ],
74
+ "TCGA-ESCA": ["esophageal carcinoma", "食道癌"],
75
+ "TCGA-GBM": ["glioblastoma multiforme", "多形性胶质母细胞瘤"],
76
+ "TCGA-HNSC": ["head and neck squamous cell carcinoma", "头颈部鳞状细胞癌"],
77
+ "TCGA-KICH": ["kidney chromophobe", "肾嫌色细胞癌"],
78
+ "TCGA-KIRC": ["kidney renal clear cell carcinoma", "肾透明细胞癌"],
79
+ "TCGA-KIRP": ["kidney renal papillary cell carcinoma", "乳头状肾细胞癌"],
80
+ "TCGA-LAML": ["acute myeloid leukemia", "急性髓系白血病"],
81
+ "TCGA-LGG": ["brain lower grade glioma", "低级别脑胶质瘤"],
82
+ "TCGA-LIHC": ["liver hepatocellular carcinoma", "肝细胞癌"],
83
+ "TCGA-LUAD": ["lung adenocarcinoma", "肺腺癌"],
84
+ "TCGA-LUSC": ["lung squamous cell carcinoma", "肺鳞状细胞癌"],
85
+ "TCGA-MESO": ["mesothelioma", "间皮瘤"],
86
+ "TCGA-OV": ["ovarian serous cystadenocarcinoma", "卵巢浆液性囊腺癌"],
87
+ "TCGA-PAAD": ["pancreatic adenocarcinoma", "胰腺腺癌"],
88
+ "TCGA-PCPG": ["pheochromocytoma and paraganglioma", "嗜铬细胞瘤和副神经节瘤"],
89
+ "TCGA-PRAD": ["prostate adenocarcinoma", "前列腺腺癌"],
90
+ "TCGA-READ": ["rectum adenocarcinoma", "直肠腺癌"],
91
+ "TCGA-SARC": ["sarcoma", "肉瘤"],
92
+ "TCGA-SKCM": ["skin cutaneous melanoma", "皮肤黑色素瘤"],
93
+ "TCGA-STAD": ["stomach adenocarcinoma", "胃腺癌"],
94
+ "TCGA-TGCT": ["testicular germ cell tumors", "睾丸生殖细胞肿瘤"],
95
+ "TCGA-THCA": ["thyroid carcinoma", "甲状腺癌"],
96
+ "TCGA-THYM": ["thymoma", "胸腺瘤"],
97
+ "TCGA-UCEC": ["uterine corpus endometrial carcinoma", "子宫体子宫内膜癌"],
98
+ "TCGA-UCS": ["uterine carcinosarcoma", "子宫癌肉瘤"],
99
+ "TCGA-UVM": ["uveal melanoma", "眼内(葡萄膜)黑色素瘤"],
100
+ }
101
+ # print(len(project_name_TCGA.keys()))
102
+ # input_query = input("请输入您要查询的 TCGA 项目名称:")
103
+ # print(project_name_TCGA[input_query])
104
+ print([k for k in project_name_TCGA.keys()])
105
+
106
+ # 支持 Markdown 和 HTML 内容格式:
107
+ # Abbreviations, Full Names and Descriptions of All Cancer Types Covered by TCGA Project.
108
+ desc = """<h1 align="center" style="font-family: Latin Modern Math, sans-serif; font-size: 22px; color: #00FF7F;">🎉 TCGA 项目涵盖的所有癌症类型的缩写、全称和描述 🧬</h1>"""
109
+ outputs = [
110
+ gr.Textbox(
111
+ label="🔎 1. 所查询的癌症类型的全称", show_copy_button=True
112
+ ), # 1. The Full Name of The Cancer Type Queried.
113
+ gr.Textbox(
114
+ label="👩‍⚕️ 2. 深入理解所查询的癌症类型",
115
+ show_copy_button=True,
116
+ ), # 2. Insight Into The Cancer Type Being Queried.
117
+ ]
118
+ my_demo = gr.Interface(
119
+ fn=demo,
120
+ inputs=[
121
+ gr.Dropdown(
122
+ choices=[k for k in project_name_TCGA.keys()],
123
+ value="TCGA-LUAD",
124
+ allow_custom_value=False,
125
+ label="⌨️ 请输入您要查询的 TCGA 项目名称,例如 TCGA-LUAD。",
126
+ ), # Please enter the name of the TCGA project you want to query, such as TCGA-LUAD.
127
+ gr.Dropdown(
128
+ choices=["Chinese", "English"],
129
+ value="Chinese",
130
+ allow_custom_value=False,
131
+ label="👨‍💻 输出语言",
132
+ ),
133
+ ],
134
+ outputs=outputs,
135
+ description=desc,
136
+ theme="JohnSmith9982/small_and_pretty",
137
+ )
138
+ my_demo.launch(show_api=False, show_error=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ openai==1.52.2
2
+ requests==2.29.0
3
+ urllib3==1.25.11
4
+ gradio==4.19.2
5
+ gradio_client==0.10.1
6
+ tenacity==8.2.3