Spaces:
Build error
Build error
Download app.py from Zaralcyld/TCMthinking: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/Zaralcyld/TCMthinking/resolve/main/app.py
- Command line
-
hf download hf://spaces/Zaralcyld/TCMthinking/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Zaralcyld/TCMthinking/resolve/main/app.py
1.99 kB
| import gradio as gr | |
| import openai | |
| #更新的OpenAPI使用 | |
| from openai import OpenAI | |
| def chat_with_gpt(apikey,prompt): | |
| client = OpenAI(api_key=apikey) | |
| # 使用 OpenAI ChatGPT API 進行對話 | |
| response = client.chat.completions.create( | |
| model="gpt-4", # 或其他您選擇的模型 | |
| messages=[ | |
| {"role": "system", "content": """ | |
| 你是一台聰明的仿寫病歷的機器人,接下來我會給你範例。之後後續我給你一段病例,希望你能夠仿造範例寫出類似的優秀紀錄,理想的優化稿,至少要產生兩次,一次初診,一次回診改善。產出病例即可,不必解說。 | |
| 範例如下:{ | |
| [診斷碼] | |
| 睡眠障礙 | |
| [原始稿] | |
| 112/12/11 多夢 難入睡 排便量少 口乾 煩躁} | |
| [理想的優化稿] | |
| 112/12/11患者自述這兩週多夢難以入睡,夜間容易醒,煩躁,半夜心悸,夜尿2-3次,排便偏硬,口乾口苦,最近吃較多炸物所致,咽喉痰梗感,小便顏色深黃。 | |
| 112/12/18 患者服藥後睡眠改善,多夢減輕,半夜易醒仍有,但頻率減少,心悸仍,但緩解許多,口乾口苦仍,小便量少,顏色深;排便有較多,每天一次排便成型。} | |
| """}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| ) | |
| content = response.choices[0].message.content | |
| return content | |
| # 建立 Gradio 介面 | |
| iface = gr.Interface( | |
| fn=chat_with_gpt, | |
| inputs=[ | |
| gr.Textbox(label="OpenAI API Key"), | |
| gr.Textbox(lines=2, placeholder="輸入您的問題...", label="Prompt") | |
| ], | |
| outputs='text', | |
| title="ChatGPT病例自動化仿寫系統", | |
| description="第一欄輸入您的 OpenAI API 金鑰,第二欄輸入您的簡化病例(譬如37歲男性,頭痛,便秘),右側將展示 ChatGPT針對簡化病例記載的擴寫版本。" | |
| ) | |
| # # # 啟動介面 | |
| iface.launch() |