Download app.py from Pal-Lab/GPT-Doc: direct link, hf CLI and curl.
- Browser
- Download file 16.3 kB
-
https://huggingface.co/spaces/Pal-Lab/GPT-Doc/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pal-Lab/GPT-Doc/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pal-Lab/GPT-Doc/resolve/main/app.py
16.3 kB
| import numpy as np | |
| import gradio as gr | |
| import openai | |
| req1 = "得られた情報をヒントに可能性のある仮説や因果モデルをいくつか提案して下さい" | |
| req2 = "疑問を明らかにするために最適な研究デザインを簡潔に提案して下さい" | |
| def generate_clinical_query_solution(text0, text1,text2, text3, text4): | |
| if text3 != "": #自由記載の相談があればそちらを優先する | |
| text2 = text3 | |
| elif text2 == "Hypothesis generation 仮説形成": | |
| text2 = req1 | |
| elif text2 == "Study design 研究デザイン": | |
| text2 = req2 | |
| query = f'''あなたは臨床研究の専門家です。以下の臨床疑問や記述について、{text2}。必ず{text4}でお答えください。Please think step by step.; | |
| {text1}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_intro_draft(text0, free_text, text6,text7, text8, text9, text4): #clinical_question, req, ori_req, lang | |
| if free_text != "": | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究の背景を踏まえて、学術論文のintroduction sectionを600文字程度で作成して下さい。必ず{text4}の文章を作成してください。Please think step by step.; | |
| {free_text}''' | |
| else: | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究の背景を踏まえて、学術論文のintroduction sectionを600文字程度で作成して下さい。必ず{text4}の文章を作成してください。Please think step by step.; | |
| What is the problem?: {text6} | |
| What do we know?: {text7} | |
| What do we need to know?: {text8} | |
| What is this study aiming to?: {text9}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_method_draft(text0, text11, text12, text13, text14, text15, text16, text17, text18, text19, text20, text21, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究方法を踏まえて、学術論文のMethod sectionを800文字以内で作成して下さい。必ず{text4}の文章を作成してください。Please think step by step.; | |
| Sudy design: {text11} | |
| Study setting: {text12} | |
| Number of participants: {text13} | |
| Inclusion criteria: {text14} | |
| Exclusion criteria: {text15} | |
| Intervention: {text16} | |
| Outcomes: {text17} | |
| Measurements: {text18} | |
| review board approval: {text19} | |
| Statistical method: {text20} | |
| others: {text21}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_results_draft(text0, text23_1, text23_2, text23_3, text23_4, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究の結果について考察を加えずに学術論文のresults sectionを600文字以内で作成して下さい。必ず{text4}の文章を作成してください。Please think step by step.; | |
| {text23_1}, {text23_2}, {text23_3}, {text23_4}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_discussions_draft(text0, text25, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究の概要を踏まえて学術論文のdiscussions sectionを1000文字以内で作成して下さい。必ず{text4}の文章を作成してください。Please think step by step.; | |
| {text25}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_discussions_draft_morita_style(text0, text25, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究の概要を踏まえて学術論文のdiscussions sectionを1000文字以内で作成して下さい。必ず{text4}で文章を作成してください。 | |
| 文章のスタイルは以下の形式に従ってください。 | |
| "This study is, to our knowledge, the first study to clarify,,, | |
| The most impoけant finding is that,,, | |
| The second important finding is that,,, | |
| Of note (interest) was that,,, | |
| Strength of this study is,,, | |
| Limitation include,,, | |
| In conclusion, ,,, " | |
| {text25}''' | |
| openai.api_key = text0 | |
| 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() | |
| def generate_abstract(text0, text27, text28, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下に示すこの研究論文を元にabstractを{text27}文字以内で作成して下さい。必ず{text4}で文章を作成してください。 | |
| 論文の内容: {text28} | |
| abstractのスタイルは以下の形式に従ってください。 | |
| Background: | |
| Method: | |
| Results: | |
| Conlusion: | |
| ''' | |
| openai.api_key = text0 | |
| 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() | |
| def free_consultation(text0, text30, text4): | |
| query = f'''あなたは臨床研究の専門家です。以下の相談に対する回答を作成して下さい。必ず{text4}で回答をお願いします。 | |
| {text30}''' | |
| openai.api_key = text0 | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| temperature=0.7, | |
| max_tokens=2048, | |
| messages=[ | |
| {"role": "user", "content": query}, | |
| ], | |
| ) | |
| return response.choices[0]["message"]["content"].strip() | |
| title = (""" | |
| <h2 align="center">📚GPT-Doc📚</h2> | |
| <h5 align="center">This is a support tool for writing papers using OpenAI-API<br>OpenAI-APIを利用した論文作成支援ツールです</h5> | |
| <h2 align="center"> </h2> | |
| ###### Potential users would be clinical research learners who use English as a second language. 利用者は英語が母国語ではない臨床研究初学者を想定しています。 | |
| ###### At first, please input your OpenAI-API-Key in Setteing tab. まずセッティングタブにOpenAI-API-Keyを入力して下さい。 | |
| ###### Please select the tab. 使用するツールを選んでください。 | |
| """) | |
| disclaimer = (""" | |
| #### Disclaimer and Precautions 注意事項及び免責事項 | |
| - This tool is not intended to complete your paper. このツールは論文の完成を目的とするものではありません。 | |
| - There is a chance that a program that detects AI-generated sentences will reject your paper when you submit it. 論文投稿の際はAIによる生成文章を見抜くプログラムによりrejectされる可能性があります。 | |
| - Some journals prohibit AI-generated sentences, so please check their submission rules. 雑誌によってはAI生成文章を禁止しているところがあるので投稿規定を確認ください。 | |
| - GPT replies may contain factually incorrect information, so please be sure to fact-check your answers. GPTの回答には事実と異なる情報が含まれることがあるので必ずファクトチェックをしてください。 | |
| - 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 disputes or damages caused by the use of information posted on this service site. 当サイトに掲載されている情報を利用することで発生した紛争や損害に対し、作成者は責任を負わないものとします。 | |
| - The creator is not responsible for any damages caused to users or third parties as a result of such content. 当該コンテンツに起因してご利用者様および第三者に損害が発生したとしても、作成者は責任を負わないものとします。 | |
| """) | |
| with gr.Blocks() as demo: | |
| gr.Markdown(title) | |
| with gr.Tab("Settings"): | |
| with gr.Column(scale=1): | |
| text0 = gr.Textbox(label="OPENAI-API-KEY", placeholder="sk-", type='password') | |
| text4 = gr.Radio(["Japanese 日本語", "English 英語"], label="Output language 出力言語", value="Japanese 日本語") | |
| with gr.Tab("Clinical Qustion Generation"): | |
| with gr.Column(scale=1): | |
| text1 = gr.Textbox(lines=2, label="Clinical question 臨床疑問", placeholder="Both formulated messages and vague tweets are acceptable. 定式化されたものでも漠然としたつぶやきでもOKです") | |
| text2 = gr.Radio(["Hypothesis generation 仮説形成", "Study design 研究デザイン"], label="Please select your request 相談内容", value="Hypothesis generation 仮説形成") | |
| text3 = gr.Textbox(lines=2, label="Create original query 相談内容を記載", placeholder="Please ask any questions. If not, please leave blank here. 上の項目の他に質問があれば記載して下さい。なければ空欄のままにしてください") | |
| cq_button = gr.Button("Generate!") | |
| text5 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Introduction"): | |
| with gr.Column(scale=1): | |
| text6 = gr.Textbox(lines=2, label="1. What is the problem? そのテーマを研究することの重要性") | |
| text7 = gr.Textbox(lines=2, label="2. What do we know? そのテーマについてこれまで研究されてきたこと") | |
| text8 = gr.Textbox(lines=2, label="3. What do we need to know? これまでの研究で課題となっていること") | |
| text9 = gr.Textbox(lines=2, label="4. What is this study aiming to? この研究の目的") | |
| free_text = gr.Textbox(lines=2, label="If you want to enter information regardless of the above structure, enter it here. ※上記構造にこだわらずに情報を入力する場合はこちら", placeholder="If you are entering 1-4 above, leave this field blank. 上の1-4に入力する場合ここは空欄のままにしてください。") | |
| intro_button = gr.Button("Generate!") | |
| text10 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Methods"): | |
| with gr.Column(scale=1): | |
| text11 = gr.Radio(["Observational study 観察研究", "Randomized controlled study 無作為化比較試験"], label="Study design 研究デザイン", value="Observational study 観察研究") | |
| text12 = gr.Textbox(lines=2, label="Setting セッティング", placeholder="Institutions, participants etc 研究に参加した施設や対象者など") | |
| text13 = gr.Textbox(lines=2, label="Number of participants 参加人数", placeholder="number of screening, included number, number of analyzed case etc スクリーニング人数、除外人数、完遂人数など") | |
| text14 = gr.Textbox(lines=2, label="Inclusion criteria 適格基準") | |
| text15 = gr.Textbox(lines=2, label="Exclusion criteria 除外基準") | |
| text16 = gr.Textbox(lines=2, label="Intervention 介入方法") | |
| text17 = gr.Textbox(lines=2, label="Main endpoint Secondary endpoint 主要評価項目、副次評価項目") | |
| text18 = gr.Textbox(lines=2, label="Measurement 測定方法") | |
| text19 = gr.Radio(["Approved 承認済", "Not approved 審査未"], label="Institutional Review Boards 倫理委員会の審査", value="Approved 承認済") | |
| text20 = gr.Textbox(lines=2, label="Statistical analysis 解析方法") | |
| text21 = gr.Textbox(lines=2, label="Other information その他必要な情報", placeholder="Please add other important information 追加したい情報があれば記載して下さい") | |
| meth_button = gr.Button("Generate!") | |
| text22 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Results"): | |
| with gr.Column(scale=1): | |
| gr.Markdown("Please input findings here. 結果を重要と思われるものから順番に入力して下さい") | |
| text23_1 = gr.Textbox(lines=2, label="Please input finding 1 here. 結果1を入力して下さい") | |
| text23_2 = gr.Textbox(lines=2, label="Please input finding 2 here. 結果2を入力して下さい") | |
| text23_3 = gr.Textbox(lines=2, label="Please input finding 3 here. 結果3を入力して下さい") | |
| text23_4 = gr.Textbox(lines=2, label="Please input other findings here. その他の結果を入力して下さい") | |
| results_button = gr.Button("Generate!") | |
| text24 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Discussions"): | |
| with gr.Column(scale=1): | |
| text25 = gr.Textbox(lines=2, label="Introduction, Methods, Resultsを入力して下さい") | |
| with gr.Row(): | |
| disc_button = gr.Button("Generate!") | |
| disc2_button = gr.Button("Generate in Morita style") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| text26 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Abstract"): | |
| with gr.Column(scale=1): | |
| text27 = gr.Number(label="Number of words 文字数") | |
| text28 = gr.Textbox(lines=2, label="Please input information such as a manuscript draft 論文本文など必要な情報を記載して下さい") | |
| abst_button = gr.Button("Generate!") | |
| text29 = gr.Textbox(lines=2, label="Answer") | |
| with gr.Tab("Free"): | |
| with gr.Column(scale=1): | |
| text30 = gr.Textbox(lines=2, label="Input anything you want to ask 何でも相談", placeholder="e.g. 'please review my writings', 'please summarize',,,英文校正して下さい、サマリーを作って下さい等") | |
| free_button = gr.Button("Generate!") | |
| text31 = gr.Textbox(lines=2, label="Answer") | |
| gr.Markdown(disclaimer) | |
| cq_button.click(generate_clinical_query_solution, inputs=[text0, text1, text2, text3, text4], outputs=text5) | |
| intro_button.click(generate_intro_draft, inputs=[text0, free_text, text6,text7, text8, text9, text4], outputs=text10) | |
| meth_button.click(generate_method_draft, inputs=[text0, text11, text12, text13, text14, text15, text16, text17, text18, text19, text20, text21, text4], outputs=text22) | |
| results_button.click(generate_results_draft, inputs=[text0, text23_1, text23_2, text23_3, text23_4, text4], outputs=text24) | |
| disc_button.click(generate_discussions_draft, inputs=[text0, text25, text4], outputs=text26) | |
| disc2_button.click(generate_discussions_draft_morita_style, inputs=[text0, text25, text4], outputs=text26) | |
| abst_button.click(generate_abstract, inputs=[text0, text27, text28, text4], outputs=text29) | |
| free_button.click(free_consultation, inputs=[text0, text30, text4], outputs=text31) | |
| demo.launch() |