Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,9 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from streamlit_option_menu import option_menu
|
4 |
-
from gemini_utility import (load_gemini_pro,
|
5 |
-
gemini_pro_vision_responce)
|
6 |
from PIL import Image
|
7 |
|
8 |
-
# To get the working directory
|
9 |
-
working_directory = os.path.dirname(os.path.abspath(__file__))
|
10 |
-
|
11 |
# Setting the page config
|
12 |
st.set_page_config(
|
13 |
page_title="GnosticDev AI",
|
@@ -16,14 +12,18 @@ st.set_page_config(
|
|
16 |
initial_sidebar_state="expanded",
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
19 |
with st.sidebar:
|
20 |
-
selected = option_menu(
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
def translate_role_to_streamlit(user_role):
|
29 |
if user_role == "model":
|
@@ -31,16 +31,44 @@ def translate_role_to_streamlit(user_role):
|
|
31 |
else:
|
32 |
return user_role
|
33 |
|
34 |
-
if selected == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
model = load_gemini_pro()
|
36 |
-
|
37 |
-
# Initialize chat session
|
38 |
if "chat_session" not in st.session_state:
|
39 |
st.session_state.chat_session = model.start_chat(history=[])
|
|
|
|
|
40 |
|
41 |
-
# Streamlit page title
|
42 |
st.title("Gnosticdev Chatbot")
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
# Display the chatbot history
|
45 |
for message in st.session_state.chat_session.history:
|
46 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
@@ -48,35 +76,22 @@ if selected == "Chatbot":
|
|
48 |
|
49 |
# Input field for user's message
|
50 |
user_prompt = st.chat_input("Preguntame algo...")
|
51 |
-
|
52 |
if user_prompt:
|
53 |
st.chat_message("user").markdown(user_prompt)
|
54 |
gemini_response = st.session_state.chat_session.send_message(user_prompt)
|
55 |
-
|
56 |
-
# Display the chatbot response
|
57 |
with st.chat_message("assistant"):
|
58 |
st.markdown(gemini_response.text)
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
# Streamlit title
|
64 |
-
st.title(" Image Caption Generation馃摳")
|
65 |
-
|
66 |
upload_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
67 |
-
|
68 |
if upload_image and st.button("Generate"):
|
69 |
image = Image.open(upload_image)
|
70 |
-
|
71 |
col1, col2 = st.columns(2)
|
72 |
-
|
73 |
with col1:
|
74 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
75 |
-
|
76 |
default_prompt = "Write a caption for this image"
|
77 |
-
|
78 |
-
# Getting the response from gemini
|
79 |
caption = gemini_pro_vision_responce(default_prompt, image)
|
80 |
-
|
81 |
with col2:
|
82 |
st.info(caption)
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from streamlit_option_menu import option_menu
|
4 |
+
from gemini_utility import (load_gemini_pro, gemini_pro_vision_responce)
|
|
|
5 |
from PIL import Image
|
6 |
|
|
|
|
|
|
|
7 |
# Setting the page config
|
8 |
st.set_page_config(
|
9 |
page_title="GnosticDev AI",
|
|
|
12 |
initial_sidebar_state="expanded",
|
13 |
)
|
14 |
|
15 |
+
# Inicializar el system prompt en session state si no existe
|
16 |
+
if "system_prompt" not in st.session_state:
|
17 |
+
st.session_state.system_prompt = ""
|
18 |
+
|
19 |
with st.sidebar:
|
20 |
+
selected = option_menu(
|
21 |
+
"GD AI",
|
22 |
+
["System Prompt", "Chatbot", "Image Captioning"],
|
23 |
+
menu_icon="robot",
|
24 |
+
icons=['gear', 'chat-dots-fill', 'image-fill'],
|
25 |
+
default_index=0
|
26 |
+
)
|
27 |
|
28 |
def translate_role_to_streamlit(user_role):
|
29 |
if user_role == "model":
|
|
|
31 |
else:
|
32 |
return user_role
|
33 |
|
34 |
+
if selected == "System Prompt":
|
35 |
+
st.title("Configuraci贸n del System Prompt")
|
36 |
+
|
37 |
+
# 脕rea para editar el system prompt
|
38 |
+
new_system_prompt = st.text_area(
|
39 |
+
"Ingresa las instrucciones para el AI (System Prompt)",
|
40 |
+
value=st.session_state.system_prompt,
|
41 |
+
height=300,
|
42 |
+
help="Escribe aqu铆 las instrucciones que definir谩n el comportamiento del AI"
|
43 |
+
)
|
44 |
+
|
45 |
+
if st.button("Guardar System Prompt"):
|
46 |
+
st.session_state.system_prompt = new_system_prompt
|
47 |
+
if "chat_session" in st.session_state:
|
48 |
+
del st.session_state.chat_session # Reset chat session
|
49 |
+
st.success("System Prompt actualizado con 茅xito!")
|
50 |
+
|
51 |
+
# Mostrar el prompt actual
|
52 |
+
if st.session_state.system_prompt:
|
53 |
+
st.markdown("### System Prompt Actual:")
|
54 |
+
st.info(st.session_state.system_prompt)
|
55 |
+
|
56 |
+
elif selected == "Chatbot":
|
57 |
model = load_gemini_pro()
|
58 |
+
|
59 |
+
# Initialize chat session with system prompt
|
60 |
if "chat_session" not in st.session_state:
|
61 |
st.session_state.chat_session = model.start_chat(history=[])
|
62 |
+
if st.session_state.system_prompt:
|
63 |
+
st.session_state.chat_session.send_message(st.session_state.system_prompt)
|
64 |
|
|
|
65 |
st.title("Gnosticdev Chatbot")
|
66 |
+
|
67 |
+
# Mostrar el system prompt actual en un expander
|
68 |
+
if st.session_state.system_prompt:
|
69 |
+
with st.expander("Ver System Prompt actual"):
|
70 |
+
st.info(st.session_state.system_prompt)
|
71 |
+
|
72 |
# Display the chatbot history
|
73 |
for message in st.session_state.chat_session.history:
|
74 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
|
|
76 |
|
77 |
# Input field for user's message
|
78 |
user_prompt = st.chat_input("Preguntame algo...")
|
|
|
79 |
if user_prompt:
|
80 |
st.chat_message("user").markdown(user_prompt)
|
81 |
gemini_response = st.session_state.chat_session.send_message(user_prompt)
|
|
|
|
|
82 |
with st.chat_message("assistant"):
|
83 |
st.markdown(gemini_response.text)
|
84 |
|
85 |
+
elif selected == "Image Captioning":
|
86 |
+
st.title("Image Caption Generation馃摳")
|
|
|
|
|
|
|
|
|
87 |
upload_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
88 |
+
|
89 |
if upload_image and st.button("Generate"):
|
90 |
image = Image.open(upload_image)
|
|
|
91 |
col1, col2 = st.columns(2)
|
|
|
92 |
with col1:
|
93 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
94 |
default_prompt = "Write a caption for this image"
|
|
|
|
|
95 |
caption = gemini_pro_vision_responce(default_prompt, image)
|
|
|
96 |
with col2:
|
97 |
st.info(caption)
|