vilarin commited on
Commit
f6fc806
·
verified ·
1 Parent(s): 7c4f4a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -11,21 +11,33 @@ api_key = os.environ.get("OPENAI_API_KEY")
11
  client = OpenAI(api_key=api_key)
12
 
13
  # Define the model to be used
14
- MODEL = "gpt-4o"
15
 
16
  def read(filename):
17
  with open(filename) as f:
18
  data = f.read()
19
  return data
20
 
21
- sys_prompt = read('system_prompt.txt')
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  def process_text(text_input, unit):
24
  if text_input:
25
  completion = client.chat.completions.create(
26
  model=MODEL,
27
  messages=[
28
- {"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
29
  {"role": "user", "content": f"Hello! Could you solve {text_input}?"}
30
  ]
31
  )
@@ -47,9 +59,9 @@ def process_image(image_input, unit):
47
  response = client.chat.completions.create(
48
  model=MODEL,
49
  messages=[
50
- {"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
51
  {"role": "user", "content": [
52
- {"type": "text", "text": "Help me understand what this image"},
53
  {"type": "image_url",
54
  "image_url": {
55
  "url": f"data:image/jpeg;base64,{base64_image}",
@@ -72,7 +84,7 @@ def main(text_input="", image_input=None, unit=""):
72
 
73
  with gr.Blocks(theme='shivi/calm_seafoam') as iface:
74
  with gr.Accordion(""):
75
- gr.Markdown("""医学报告助手 GPT-4o""")
76
  unit = gr.Dropdown(label="🩺科室", value='内科', elem_id="units",
77
  choices=["内科", "外科", "妇产科", "男科", "儿科", \
78
  "五官科", "肿瘤科", "皮肤性病科", "中医科", "传染科", "精神心理科", \
@@ -89,6 +101,8 @@ with gr.Blocks(theme='shivi/calm_seafoam') as iface:
89
 
90
  # Set up the event listeners
91
  submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
 
 
92
 
93
  #gr.close_all()
94
 
 
11
  client = OpenAI(api_key=api_key)
12
 
13
  # Define the model to be used
14
+ MODEL = os.environ.get("MODEL")
15
 
16
  def read(filename):
17
  with open(filename) as f:
18
  data = f.read()
19
  return data
20
 
21
+ SYS_PROMPT = read('system_prompt.txt')
22
+
23
+
24
+ DESCRIPTION = '''
25
+ <div>
26
+ <h1 style="text-align: center;">诊疗助手</h1>
27
+ <p>一个帮助您分析症状和检验报告的AI工具。</p>
28
+ <p>🔎 选择您需要咨询的科室,在输入框中输入症状描述或者体检信息等;您也可以在图片框中上传检测报告图。</p>
29
+ <p>🦕 请注意生成信息可能不准确,且不具备任何实际参考价值,如有需要请联系专业医生。</p>
30
+ </div>
31
+ '''
32
+
33
+ LICENSE = '采用' + MODEL + '模型'
34
 
35
  def process_text(text_input, unit):
36
  if text_input:
37
  completion = client.chat.completions.create(
38
  model=MODEL,
39
  messages=[
40
+ {"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
41
  {"role": "user", "content": f"Hello! Could you solve {text_input}?"}
42
  ]
43
  )
 
59
  response = client.chat.completions.create(
60
  model=MODEL,
61
  messages=[
62
+ {"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
63
  {"role": "user", "content": [
64
+ {"type": "text", "text": "Help me understand what is in this picture and analysis."},
65
  {"type": "image_url",
66
  "image_url": {
67
  "url": f"data:image/jpeg;base64,{base64_image}",
 
84
 
85
  with gr.Blocks(theme='shivi/calm_seafoam') as iface:
86
  with gr.Accordion(""):
87
+ gr.Markdown(DESCRIPTION)
88
  unit = gr.Dropdown(label="🩺科室", value='内科', elem_id="units",
89
  choices=["内科", "外科", "妇产科", "男科", "儿科", \
90
  "五官科", "肿瘤科", "皮肤性病科", "中医科", "传染科", "精神心理科", \
 
101
 
102
  # Set up the event listeners
103
  submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
104
+
105
+ gr.Markdown(LICENSE)
106
 
107
  #gr.close_all()
108