Spaces:
Running
Running
Update app.py
Browse filesSystem prompts are updated with system instructions.
app.py
CHANGED
@@ -14,6 +14,7 @@ load_dotenv()
|
|
14 |
# Set the Gemini API Key
|
15 |
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
|
16 |
|
|
|
17 |
# Set up the model configuration for content generation
|
18 |
generation_config = {
|
19 |
"temperature": 0.4,
|
@@ -33,21 +34,10 @@ safety_settings = [
|
|
33 |
]
|
34 |
]
|
35 |
|
36 |
-
# Create the Gemini Models for Text and Vision respectively
|
37 |
-
txt_model = genai.GenerativeModel(
|
38 |
-
model_name="gemini-1.5-pro",
|
39 |
-
generation_config=generation_config,
|
40 |
-
safety_settings=safety_settings,
|
41 |
-
)
|
42 |
-
vis_model = genai.GenerativeModel(
|
43 |
-
model_name="gemini-pro-vision",
|
44 |
-
generation_config=generation_config,
|
45 |
-
safety_settings=safety_settings,
|
46 |
-
)
|
47 |
|
48 |
# System Prompt
|
49 |
system_prompt = """
|
50 |
-
|
51 |
|
52 |
**Analysis Guidelines:**
|
53 |
|
@@ -61,10 +51,29 @@ Model: "As a trusted medical chatbot, your role is crucial in providing accurate
|
|
61 |
**Refusal Policy:**
|
62 |
If the user provides information not related to reducing neonatal and under-five mortality rates, maternal health, or women's health issues, kindly inform them that this chatbot is designed to address queries specific to these global health goals. Encourage them to seek assistance from appropriate sources for other inquiries.
|
63 |
|
64 |
-
Your role as a medical chatbot is to provide valuable insights and recommendations to support efforts in reducing preventable deaths of newborns and children under 5 years of age, as well as improving maternal and women's health outcomes. Proceed to assist users with their queries, ensuring clarity, empathy, and accuracy in your responses.
|
65 |
|
66 |
"""
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# HTML Content for the Interface
|
69 |
TITLE = """<h1 align="center">Well Being π¬</h1>"""
|
70 |
SUBTITLE = """<h2 align="center">End Preventable Child Deaths: Join the Global Effort to Save Children's Lives!</h2>"""
|
@@ -158,14 +167,12 @@ def llm_response(history, text, img):
|
|
158 |
if not img:
|
159 |
# response = txt_model.generate_content(f"{system_prompt}User: {text}")
|
160 |
chat_session = txt_model.start_chat(history=[])
|
161 |
-
response = chat_session.send_message(
|
162 |
-
f"{system_prompt}History:\n{history_str}\nUser: {text}"
|
163 |
-
)
|
164 |
else:
|
165 |
# Open Image and Generate Response
|
166 |
img = PIL.Image.open(img)
|
167 |
chat_session = vis_model.start_chat(history=[])
|
168 |
-
response = chat_session.send_message([f"
|
169 |
|
170 |
# response = vis_model.generate_content([f"{system_prompt}User: {text}", img])
|
171 |
|
|
|
14 |
# Set the Gemini API Key
|
15 |
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
|
16 |
|
17 |
+
|
18 |
# Set up the model configuration for content generation
|
19 |
generation_config = {
|
20 |
"temperature": 0.4,
|
|
|
34 |
]
|
35 |
]
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# System Prompt
|
39 |
system_prompt = """
|
40 |
+
As a trusted medical chatbot, your role is crucial in providing accurate information and guidance to users seeking assistance in reducing preventable deaths of newborns and children under 5 years of age, as well as supporting the health and well-being of pregnant mothers and women. Your focus will be on addressing queries related to neonatal and under-five mortality rates, maternal health, and women's health issues, offering insights and recommendations to support these global health goals.
|
41 |
|
42 |
**Analysis Guidelines:**
|
43 |
|
|
|
51 |
**Refusal Policy:**
|
52 |
If the user provides information not related to reducing neonatal and under-five mortality rates, maternal health, or women's health issues, kindly inform them that this chatbot is designed to address queries specific to these global health goals. Encourage them to seek assistance from appropriate sources for other inquiries.
|
53 |
|
54 |
+
Your role as a medical chatbot is to provide valuable insights and recommendations to support efforts in reducing preventable deaths of newborns and children under 5 years of age, as well as improving maternal and women's health outcomes. Proceed to assist users with their queries, ensuring clarity, empathy, and accuracy in your responses.
|
55 |
|
56 |
"""
|
57 |
|
58 |
+
|
59 |
+
# Define the model name
|
60 |
+
model_name = "gemini-1.5-pro"
|
61 |
+
|
62 |
+
# Create the Gemini Models for Text and Vision respectively
|
63 |
+
txt_model = genai.GenerativeModel(
|
64 |
+
model_name=model_name,
|
65 |
+
generation_config=generation_config,
|
66 |
+
safety_settings=safety_settings,
|
67 |
+
system_instruction=system_prompt,
|
68 |
+
)
|
69 |
+
vis_model = genai.GenerativeModel(
|
70 |
+
model_name=model_name,
|
71 |
+
generation_config=generation_config,
|
72 |
+
safety_settings=safety_settings,
|
73 |
+
system_instruction=system_prompt,
|
74 |
+
)
|
75 |
+
|
76 |
+
|
77 |
# HTML Content for the Interface
|
78 |
TITLE = """<h1 align="center">Well Being π¬</h1>"""
|
79 |
SUBTITLE = """<h2 align="center">End Preventable Child Deaths: Join the Global Effort to Save Children's Lives!</h2>"""
|
|
|
167 |
if not img:
|
168 |
# response = txt_model.generate_content(f"{system_prompt}User: {text}")
|
169 |
chat_session = txt_model.start_chat(history=[])
|
170 |
+
response = chat_session.send_message(f"History:\n{history_str}\nUser: {text}")
|
|
|
|
|
171 |
else:
|
172 |
# Open Image and Generate Response
|
173 |
img = PIL.Image.open(img)
|
174 |
chat_session = vis_model.start_chat(history=[])
|
175 |
+
response = chat_session.send_message([f"User: {text}", img])
|
176 |
|
177 |
# response = vis_model.generate_content([f"{system_prompt}User: {text}", img])
|
178 |
|