Update app.py
Browse files
app.py
CHANGED
|
@@ -5,28 +5,23 @@ import os
|
|
| 5 |
import io
|
| 6 |
import base64
|
| 7 |
|
| 8 |
-
# Set API key
|
| 9 |
-
api_key = os.environ.get("OPENAI_API_KEY")
|
| 10 |
#base_url = os.environ.get("OPENAI_API_BASE")
|
|
|
|
| 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;"
|
| 27 |
-
<p
|
| 28 |
-
<p>🔎
|
| 29 |
-
<p>🦕
|
| 30 |
</div>
|
| 31 |
'''
|
| 32 |
|
|
@@ -42,7 +37,12 @@ footer {
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
|
| 45 |
-
LICENSE = '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def process_text(text_input, unit):
|
| 48 |
if text_input:
|
|
@@ -95,22 +95,24 @@ def main(text_input="", image_input=None, unit=""):
|
|
| 95 |
with gr.Blocks(theme='shivi/calm_seafoam', css=css, title="诊疗助手Alpha") as iface:
|
| 96 |
with gr.Accordion(""):
|
| 97 |
gr.Markdown(DESCRIPTION)
|
| 98 |
-
unit = gr.Dropdown(label="
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
with gr.Row():
|
| 104 |
-
|
| 105 |
with gr.Row():
|
| 106 |
-
image_input = gr.Image(type="pil", label="
|
| 107 |
-
text_input = gr.Textbox(label="
|
| 108 |
with gr.Row():
|
| 109 |
-
submit_btn = gr.Button("🚀
|
| 110 |
-
clear_btn = gr.ClearButton(output_box, value="🗑️
|
| 111 |
|
| 112 |
# Set up the event listeners
|
| 113 |
-
submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
|
| 114 |
|
| 115 |
gr.Markdown(LICENSE)
|
| 116 |
|
|
|
|
| 5 |
import io
|
| 6 |
import base64
|
| 7 |
|
| 8 |
+
# Set API key
|
|
|
|
| 9 |
#base_url = os.environ.get("OPENAI_API_BASE")
|
| 10 |
+
api_key = ""
|
| 11 |
client = OpenAI(api_key=api_key)
|
| 12 |
|
| 13 |
# Define the model to be used
|
| 14 |
MODEL = os.environ.get("MODEL")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
SYS_PROMPT = read('system_prompt.txt')
|
| 17 |
|
| 18 |
|
| 19 |
DESCRIPTION = '''
|
| 20 |
<div>
|
| 21 |
+
<h1 style="text-align: center;">Medster - Diagnostic Assistant</h1>
|
| 22 |
+
<p>An AI tool that helps you analyze symptoms and test reports. </p>
|
| 23 |
+
<p>🔎 Select the department you need to consult, and enter the symptom description or physical examination information in the input box; you can also upload the test report image in the picture box. </p>
|
| 24 |
+
<p>🦕 Please note that the generated information may be inaccurate and does not have any actual reference value. Please contact a professional doctor if necessary. </p>
|
| 25 |
</div>
|
| 26 |
'''
|
| 27 |
|
|
|
|
| 37 |
"""
|
| 38 |
|
| 39 |
|
| 40 |
+
LICENSE = 'MODEL: ' + MODEL + ' LOADED'
|
| 41 |
+
|
| 42 |
+
def read(filename):
|
| 43 |
+
with open(filename) as f:
|
| 44 |
+
data = f.read()
|
| 45 |
+
return data
|
| 46 |
|
| 47 |
def process_text(text_input, unit):
|
| 48 |
if text_input:
|
|
|
|
| 95 |
with gr.Blocks(theme='shivi/calm_seafoam', css=css, title="诊疗助手Alpha") as iface:
|
| 96 |
with gr.Accordion(""):
|
| 97 |
gr.Markdown(DESCRIPTION)
|
| 98 |
+
unit = gr.Dropdown(label="🩺Department", value='Traditional Chinese Medicine', elem_id="units",
|
| 99 |
+
choices=["Traditional Medicine", "Internal Medicine", "Surgery", "Obstetrics and Gynecology", "Pediatrics", \
|
| 100 |
+
"Orthodontics", "Andrology", "Dermatology and Venereology", "Infectious Diseases", "Psychiatry", \
|
| 101 |
+
"Plastic Surgery Department", "Nutrition Department", "Reproductive Center", "Anesthesiology Department", "Medical Imaging Department", \
|
| 102 |
+
"Orthopedics", "Oncology", "Emergency Department", "Laboratory Department"])
|
| 103 |
+
with gr.Row():
|
| 104 |
+
output_box = gr.Markdown(label="Diagnosis") # Create an output textbox
|
| 105 |
with gr.Row():
|
| 106 |
+
api_key = gr.Textbox(label="OpenAI API Key") # Input API key
|
| 107 |
with gr.Row():
|
| 108 |
+
image_input = gr.Image(type="pil", label="Upload Image") # Create an image upload button
|
| 109 |
+
text_input = gr.Textbox(label="Submit") # Create a text input box
|
| 110 |
with gr.Row():
|
| 111 |
+
submit_btn = gr.Button("🚀 Send") # Create a submit button
|
| 112 |
+
clear_btn = gr.ClearButton(output_box, value="🗑️ Clear") # Create a clear button
|
| 113 |
|
| 114 |
# Set up the event listeners
|
| 115 |
+
submit_btn.click(main, inputs=[apiKey, text_input, image_input, unit], outputs=output_box)
|
| 116 |
|
| 117 |
gr.Markdown(LICENSE)
|
| 118 |
|