Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,17 @@ from openai import OpenAI
|
|
| 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 phenotype and effective prevention 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.
|
|
@@ -28,6 +29,7 @@ Your task is to analyze in depth the phenotype and effective prevention of {name
|
|
| 28 |
max_retries=3,
|
| 29 |
timeout=60,
|
| 30 |
)
|
|
|
|
| 31 |
# 调用 client.chat.completions.create,设置关键参数。
|
| 32 |
chat_completion = client.chat.completions.create(
|
| 33 |
model="gpt-4-turbo", # gpt-4o-mini-2024-07-18
|
|
@@ -45,10 +47,14 @@ Your task is to analyze in depth the phenotype and effective prevention of {name
|
|
| 45 |
frequency_penalty=0.20,
|
| 46 |
)
|
| 47 |
resp_text = chat_completion.choices[0].message.content.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# 在普通文本框不能用 "**" 渲染加粗,Markdown 才可以。因此,将输入字符串中所有的 "**" 替换为 ""。
|
| 50 |
-
if "**" in resp_text:
|
| 51 |
-
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
print(str(e), "Response Error")
|
|
@@ -112,7 +118,7 @@ outputs = [
|
|
| 112 |
gr.Textbox(
|
| 113 |
label="🔎 1. 您查询的 TCGA 项目的癌症类型的全称", show_copy_button=True
|
| 114 |
), # 1. The Full Name of The Cancer Type Queried.
|
| 115 |
-
gr.
|
| 116 |
label="👩⚕️ 2. 快速了解您查询的这种癌症类型",
|
| 117 |
show_copy_button=True,
|
| 118 |
), # 2. Insight Into The Cancer Type Being Queried. A Quick Look At The Cancer Type Being Queried
|
|
|
|
| 5 |
|
| 6 |
def demo(project_TCGA, output_language="Chinese"):
|
| 7 |
name_English, name_Chinese = project_name_TCGA[project_TCGA]
|
| 8 |
+
tcga_link = f"https://portal.gdc.cancer.gov/projects/{project_TCGA}"
|
| 9 |
output1, output2 = None, None
|
| 10 |
|
| 11 |
if output_language == "Chinese":
|
| 12 |
+
output1 = f"✍️ 简称:{project_TCGA}\n❤️ 中文全称:{name_Chinese}\n💛 英文全称:{name_English}\n🔗 链接:{tcga_link}"
|
| 13 |
system_instruction = f"您是系统生物学、流行病学、癌症研究和精准医学领域的专家,对{name_Chinese}有着深刻的洞察。"
|
| 14 |
prompt_template = f"""
|
| 15 |
您的任务是深入分析{name_Chinese}这种复杂疾病的表型和有效预防,并深入探索其发病和进展中涉及的关键的分子机制与信号通路。让我们一步一步地思考。
|
| 16 |
""".strip()
|
| 17 |
else:
|
| 18 |
+
output1 = f"✍️ Abbreviation: {project_TCGA}\n❤️ Full name in Chinese: {name_Chinese}\n💛 Full Name in English: {name_English}\n🔗 Link:{tcga_link}"
|
| 19 |
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}."
|
| 20 |
prompt_template = f"""
|
| 21 |
Your task is to analyze in depth the phenotype and effective prevention 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.
|
|
|
|
| 29 |
max_retries=3,
|
| 30 |
timeout=60,
|
| 31 |
)
|
| 32 |
+
|
| 33 |
# 调用 client.chat.completions.create,设置关键参数。
|
| 34 |
chat_completion = client.chat.completions.create(
|
| 35 |
model="gpt-4-turbo", # gpt-4o-mini-2024-07-18
|
|
|
|
| 47 |
frequency_penalty=0.20,
|
| 48 |
)
|
| 49 |
resp_text = chat_completion.choices[0].message.content.strip()
|
| 50 |
+
if output_language == "Chinese":
|
| 51 |
+
resp_text = "请注意:以下内容是通过提示工程驱动的 GPT-4 Turbo 生成的\n" + resp_text
|
| 52 |
+
else:
|
| 53 |
+
resp_text = "Please note: The following content is generated by prompt engineering to drive the GPT-4 Turbo\n" + resp_text
|
| 54 |
|
| 55 |
# 在普通文本框不能用 "**" 渲染加粗,Markdown 才可以。因此,将输入字符串中所有的 "**" 替换为 ""。
|
| 56 |
+
# if "**" in resp_text:
|
| 57 |
+
# output2 = resp_text.replace("**", "")
|
| 58 |
|
| 59 |
except Exception as e:
|
| 60 |
print(str(e), "Response Error")
|
|
|
|
| 118 |
gr.Textbox(
|
| 119 |
label="🔎 1. 您查询的 TCGA 项目的癌症类型的全称", show_copy_button=True
|
| 120 |
), # 1. The Full Name of The Cancer Type Queried.
|
| 121 |
+
gr.Markdown(
|
| 122 |
label="👩⚕️ 2. 快速了解您查询的这种癌症类型",
|
| 123 |
show_copy_button=True,
|
| 124 |
), # 2. Insight Into The Cancer Type Being Queried. A Quick Look At The Cancer Type Being Queried
|