Download app.py from Pal-Lab/Ethics-Conflict-Resolver-Demo: direct link, hf CLI and curl.
- Browser
- Download file 3.72 kB
-
https://huggingface.co/spaces/Pal-Lab/Ethics-Conflict-Resolver-Demo/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pal-Lab/Ethics-Conflict-Resolver-Demo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pal-Lab/Ethics-Conflict-Resolver-Demo/resolve/main/app.py
3.72 kB
| import gradio as gr | |
| import openai | |
| import os | |
| req1 = "倫理的なジレンマを整理して箇条書きで示して下さい。" | |
| req2 = f"""次に示すJonsenの倫理的な4つの枠組みに基づき簡潔にまとめて下さい。 | |
| 1.医学的適応 | |
| 2.患者の選好 | |
| 3.QOL | |
| 4.周囲の状況(医療者・医療施設側の利益相反、家族・利害関係者、経済的問題、宗教、法律など)""" | |
| req3 = "倫理的な問題解決のために、さらに情報収集すべき課題を抽出して下さい。" | |
| openai.api_key = os.getenv('openai_api_key') | |
| disclaimer = (""" | |
| #### 注意事項及び免責事項 Disclaimer and Precautions | |
| ###### このツールは問題解決をAIに全て委ねることを目的とするものではありません。 This tool is not intended to generate complete answer. | |
| ###### ご利用はご自身の責任において行ってください。本ツールにより生じたいかなる損害についても、作成者は責任を負いかねます。 Use of this tool is at your own risk. The creator cannot be held responsible for any harm caused by this tool. | |
| ###### 当該コンテンツに起因してご利用者様および第三者に損害が発生したとしても作成者は責任を負わないものとします。 The creator is not responsible for any damages caused to users or third parties as a result of such content. | |
| """) | |
| def generate_ethical_answers(case_summary, req, ori_req, lang): | |
| if ori_req != "": #自由記載の相談があればそちらを優先する | |
| req = ori_req | |
| elif req == "倫理的問題の整理 Summarize": | |
| req = req1 | |
| elif req == "4分割法に基づく整理 Summarize Ethical Problems in Jonsen's Four Paradigm": | |
| req = req2 | |
| elif req == "さらに情報が必要な問題点の抽出 Extracting Unidentified information": | |
| req = req3 | |
| query = f'''あなたは臨床倫理の専門家です。以下の事例について、{req}。必ず{lang}でお答えください。Please think step by step. ; | |
| 相談事例の概要: {case_summary}''' | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| temperature=0.7, | |
| max_tokens=1024, | |
| messages=[ | |
| {"role": "user", "content": query}, | |
| ], | |
| ) | |
| return response.choices[0]["message"]["content"].strip() | |
| iface = gr.Interface( | |
| fn=generate_ethical_answers, | |
| inputs=[ | |
| gr.inputs.Textbox(lines=2, label="相談事例の概要 Patient's age, sex, disease, history etc", placeholder="当事者の年齢、性別、疾患名、経過など"), | |
| gr.inputs.Radio(["倫理的問題の整理 Summarize", "4分割法に基づく整理 Summarize ethical problems in Jonsen's Four Paradigm", "さらに情報が必要な問題点の抽出 Extracting Unidentified information"], label="相談内容 Please select your request"), | |
| gr.inputs.Textbox(lines=2, label="相談内容を記載 Create original query", placeholder="上の3項目の他に質問があれば記載して下さい。なければ空欄のままにしてください。"), | |
| gr.inputs.Radio(["日本語 Japanese", "英語 English"], label="言語 Preferred Language"), | |
| ], | |
| outputs=gr.outputs.Textbox(label="倫理的な問題と解決策 Suggestions"), | |
| title="臨床倫理サポートツール Medical Ethics Conflict Resolver", | |
| description= "これはGPTを用いて実際の事例情報を元に倫理的問題を整理するためのツールです. This tool would help you summarize conflicts and suggest some solutions using GPT technology", | |
| article= (disclaimer), | |
| allow_flagging='never', | |
| ) | |
| iface.launch() | |