Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ api_key = ""
|
|
| 13 |
endpoints = ''
|
| 14 |
|
| 15 |
# Define the model to be used
|
| 16 |
-
|
| 17 |
|
| 18 |
DESCRIPTION = '''
|
| 19 |
<div>
|
|
@@ -42,8 +42,10 @@ LICENSE = 'MODEL: ' + MODEL + ' LOADED'
|
|
| 42 |
def endpoints(api_key):
|
| 43 |
if api_key is not None:
|
| 44 |
if api_key[:3] == "sk-":
|
|
|
|
| 45 |
return 'OPENAI'
|
| 46 |
else:
|
|
|
|
| 47 |
return 'GOOGLE'
|
| 48 |
return
|
| 49 |
|
|
@@ -60,7 +62,7 @@ def process_text(text_input, unit):
|
|
| 60 |
if text_input and endpoints == 'OPENAI':
|
| 61 |
client = OpenAI(api_key=api_key)
|
| 62 |
completion = client.chat.completions.create(
|
| 63 |
-
model=
|
| 64 |
messages=[
|
| 65 |
{"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
|
| 66 |
{"role": "user", "content": f"Hello! Could you solve {text_input}?"}
|
|
@@ -69,7 +71,7 @@ def process_text(text_input, unit):
|
|
| 69 |
return completion.choices[0].message.content
|
| 70 |
elif text_input and endpoints == "GOOGLE":
|
| 71 |
genai.configure(api_key=api_key)
|
| 72 |
-
model = genai.GenerativeModel(
|
| 73 |
response = model.generate_content(f" You are a experienced {unit} doctor." + SYS_PROMPT + f"Could you solve {text_input}?")
|
| 74 |
return response.text
|
| 75 |
return ""
|
|
@@ -87,7 +89,7 @@ def process_image(image_input, unit):
|
|
| 87 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
| 88 |
base64_image = encode_image_to_base64(image_input)
|
| 89 |
response = client.chat.completions.create(
|
| 90 |
-
model=
|
| 91 |
messages=[
|
| 92 |
{"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
|
| 93 |
{"role": "user", "content": [
|
|
@@ -103,9 +105,9 @@ def process_image(image_input, unit):
|
|
| 103 |
max_tokens=1024,
|
| 104 |
)
|
| 105 |
return response.choices[0].message.content
|
| 106 |
-
elif image_input is not None and
|
| 107 |
genai.configure(api_key=api_key)
|
| 108 |
-
model = genai.GenerativeModel(
|
| 109 |
response = model.generate_content([f" You are a experienced {unit} doctor." + SYS_PROMPT + "Help me understand what is in this picture and analysis.", image_input])
|
| 110 |
return response.text
|
| 111 |
|
|
@@ -126,7 +128,7 @@ with gr.Blocks(theme='shivi/calm_seafoam', css=css, title="Medster - Medical Dia
|
|
| 126 |
with gr.Row():
|
| 127 |
output_box = gr.Markdown(label="Diagnosis") # Create an output textbox
|
| 128 |
with gr.Row():
|
| 129 |
-
api_key = gr.Textbox(label="API Key") # Input API key
|
| 130 |
with gr.Row():
|
| 131 |
image_input = gr.Image(type="pil", label="Upload Image") # Create an image upload button
|
| 132 |
text_input = gr.Textbox(label="Submit") # Create a text input box
|
|
|
|
| 13 |
endpoints = ''
|
| 14 |
|
| 15 |
# Define the model to be used
|
| 16 |
+
model_name = ""
|
| 17 |
|
| 18 |
DESCRIPTION = '''
|
| 19 |
<div>
|
|
|
|
| 42 |
def endpoints(api_key):
|
| 43 |
if api_key is not None:
|
| 44 |
if api_key[:3] == "sk-":
|
| 45 |
+
model_name = "gpt-4o"
|
| 46 |
return 'OPENAI'
|
| 47 |
else:
|
| 48 |
+
model_name = "models/gemini-1.5-pro-latest"
|
| 49 |
return 'GOOGLE'
|
| 50 |
return
|
| 51 |
|
|
|
|
| 62 |
if text_input and endpoints == 'OPENAI':
|
| 63 |
client = OpenAI(api_key=api_key)
|
| 64 |
completion = client.chat.completions.create(
|
| 65 |
+
model=model_name,
|
| 66 |
messages=[
|
| 67 |
{"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
|
| 68 |
{"role": "user", "content": f"Hello! Could you solve {text_input}?"}
|
|
|
|
| 71 |
return completion.choices[0].message.content
|
| 72 |
elif text_input and endpoints == "GOOGLE":
|
| 73 |
genai.configure(api_key=api_key)
|
| 74 |
+
model = genai.GenerativeModel(model_name=model_name),
|
| 75 |
response = model.generate_content(f" You are a experienced {unit} doctor." + SYS_PROMPT + f"Could you solve {text_input}?")
|
| 76 |
return response.text
|
| 77 |
return ""
|
|
|
|
| 89 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
| 90 |
base64_image = encode_image_to_base64(image_input)
|
| 91 |
response = client.chat.completions.create(
|
| 92 |
+
model=model_name,
|
| 93 |
messages=[
|
| 94 |
{"role": "system", "content": f" You are a experienced {unit} doctor." + SYS_PROMPT},
|
| 95 |
{"role": "user", "content": [
|
|
|
|
| 105 |
max_tokens=1024,
|
| 106 |
)
|
| 107 |
return response.choices[0].message.content
|
| 108 |
+
elif image_input is not None and endpoints == "GOOGLE":
|
| 109 |
genai.configure(api_key=api_key)
|
| 110 |
+
model = genai.GenerativeModel(model_name=model_name),
|
| 111 |
response = model.generate_content([f" You are a experienced {unit} doctor." + SYS_PROMPT + "Help me understand what is in this picture and analysis.", image_input])
|
| 112 |
return response.text
|
| 113 |
|
|
|
|
| 128 |
with gr.Row():
|
| 129 |
output_box = gr.Markdown(label="Diagnosis") # Create an output textbox
|
| 130 |
with gr.Row():
|
| 131 |
+
api_key = gr.Textbox(label="API Key", type='password') # Input API key
|
| 132 |
with gr.Row():
|
| 133 |
image_input = gr.Image(type="pil", label="Upload Image") # Create an image upload button
|
| 134 |
text_input = gr.Textbox(label="Submit") # Create a text input box
|