Update app.py
Browse files
app.py
CHANGED
@@ -24,10 +24,10 @@ SYS_PROMPT = read('system_prompt.txt')
|
|
24 |
|
25 |
DESCRIPTION = '''
|
26 |
<div>
|
27 |
-
<h1 style="text-align: center;"
|
28 |
-
<p
|
29 |
-
<p>🔎
|
30 |
-
<p>🦕
|
31 |
</div>
|
32 |
'''
|
33 |
|
@@ -59,15 +59,15 @@ def process_text(text_input, unit):
|
|
59 |
completion = client.chat.completions.create(
|
60 |
model=MODEL,
|
61 |
messages=[
|
62 |
-
{"role": "system", "content": f" You are a experienced {unit}
|
63 |
-
{"role": "user", "content": f"Hello! Could you
|
64 |
]
|
65 |
)
|
66 |
return completion.choices[0].message.content
|
67 |
elif text_input and endpoint == 'GOOGLE':
|
68 |
genai.configure(api_key=api_key)
|
69 |
model = genai.GenerativeModel(model_name=MODEL)
|
70 |
-
prompt = f" You are a experienced {unit}
|
71 |
response = model.generate_content(prompt)
|
72 |
return response.text
|
73 |
return ""
|
@@ -88,7 +88,7 @@ def process_image(image_input, unit):
|
|
88 |
response = client.chat.completions.create(
|
89 |
model=MODEL,
|
90 |
messages=[
|
91 |
-
{"role": "system", "content": f" You are a experienced {unit}
|
92 |
{"role": "user", "content": [
|
93 |
{"type": "text", "text": "Help me understand what is in this picture and analysis."},
|
94 |
{"type": "image_url",
|
@@ -105,7 +105,7 @@ def process_image(image_input, unit):
|
|
105 |
elif image_input is not None and endpoint == 'GOOGLE':
|
106 |
genai.configure(api_key=api_key)
|
107 |
model = genai.GenerativeModel(model_name=MODEL)
|
108 |
-
prompt = f" You are a experienced {unit}
|
109 |
response = model.generate_content([prompt, image_input],request_options={"timeout": 60})
|
110 |
return response.text
|
111 |
|
@@ -116,14 +116,12 @@ def main(text_input="", image_input=None, unit=""):
|
|
116 |
elif image_input is not None:
|
117 |
return process_image(image_input,unit)
|
118 |
|
119 |
-
with gr.Blocks(theme='shivi/calm_seafoam', css=css, title="
|
120 |
with gr.Accordion(""):
|
121 |
gr.Markdown(DESCRIPTION)
|
122 |
-
unit = gr.Dropdown(label="
|
123 |
-
choices=["
|
124 |
-
"
|
125 |
-
"整形美容科", "营养科", "生殖中心", "麻醉医学科", "医学影像科", \
|
126 |
-
"骨科", "肿瘤科", "急诊科", "检验科"])
|
127 |
with gr.Row():
|
128 |
output_box = gr.Markdown(label="分析") # Create an output textbox
|
129 |
with gr.Row():
|
|
|
24 |
|
25 |
DESCRIPTION = '''
|
26 |
<div>
|
27 |
+
<h1 style="text-align: center;">知觉demo</h1>
|
28 |
+
<p>🩺一个基于提示词和前沿多模态模型的AI,帮助您解读专业领域内容。</p>
|
29 |
+
<p>🔎 您可以选择领域,参考示例上传图像,或发送需要解读的文字内容。</p>
|
30 |
+
<p>🦕 生成解读内容仅供参考。</p>
|
31 |
</div>
|
32 |
'''
|
33 |
|
|
|
59 |
completion = client.chat.completions.create(
|
60 |
model=MODEL,
|
61 |
messages=[
|
62 |
+
{"role": "system", "content": f" You are a experienced Analyst in {unit}." + SYS_PROMPT},
|
63 |
+
{"role": "user", "content": f"Hello! Could you analysis {text_input}?"}
|
64 |
]
|
65 |
)
|
66 |
return completion.choices[0].message.content
|
67 |
elif text_input and endpoint == 'GOOGLE':
|
68 |
genai.configure(api_key=api_key)
|
69 |
model = genai.GenerativeModel(model_name=MODEL)
|
70 |
+
prompt = f" You are a experienced Analyst in {unit}." + SYS_PROMPT + f"Could you analysis {text_input}?"
|
71 |
response = model.generate_content(prompt)
|
72 |
return response.text
|
73 |
return ""
|
|
|
88 |
response = client.chat.completions.create(
|
89 |
model=MODEL,
|
90 |
messages=[
|
91 |
+
{"role": "system", "content": f" You are a experienced Analyst in {unit}." + SYS_PROMPT},
|
92 |
{"role": "user", "content": [
|
93 |
{"type": "text", "text": "Help me understand what is in this picture and analysis."},
|
94 |
{"type": "image_url",
|
|
|
105 |
elif image_input is not None and endpoint == 'GOOGLE':
|
106 |
genai.configure(api_key=api_key)
|
107 |
model = genai.GenerativeModel(model_name=MODEL)
|
108 |
+
prompt = f" You are a experienced Analyst in {unit}." + SYS_PROMPT + "Help me understand what is in this picture and analysis it."
|
109 |
response = model.generate_content([prompt, image_input],request_options={"timeout": 60})
|
110 |
return response.text
|
111 |
|
|
|
116 |
elif image_input is not None:
|
117 |
return process_image(image_input,unit)
|
118 |
|
119 |
+
with gr.Blocks(theme='shivi/calm_seafoam', css=css, title="知觉demo") as iface:
|
120 |
with gr.Accordion(""):
|
121 |
gr.Markdown(DESCRIPTION)
|
122 |
+
unit = gr.Dropdown(label="领域", value='财经', elem_id="units",
|
123 |
+
choices=["财经", "市场", "产业", "国际关系", "医疗", \
|
124 |
+
"SEO", "评估", "科技", "策划", "营销"])
|
|
|
|
|
125 |
with gr.Row():
|
126 |
output_box = gr.Markdown(label="分析") # Create an output textbox
|
127 |
with gr.Row():
|