Spaces:
Runtime error
Runtime error
Upload 7 files
Browse files- .streamlit/config.toml +5 -5
- Readme.md +71 -0
- app.py +5 -3
- assets/robocopy_logo.png +0 -0
.streamlit/config.toml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
[theme]
|
2 |
-
primaryColor="#
|
3 |
-
backgroundColor="#
|
4 |
-
secondaryBackgroundColor="#
|
5 |
-
textColor="#
|
6 |
-
font="serif"
|
7 |
# 335095
|
|
|
1 |
[theme]
|
2 |
+
primaryColor = "#4ECDC4" # Color turquesa similar al del logo
|
3 |
+
backgroundColor = "#1A1A1A" # Fondo oscuro para resaltar los elementos
|
4 |
+
secondaryBackgroundColor = "#252A34" # Gris oscuro para paneles
|
5 |
+
textColor = "#FFFFFF" # Texto blanco para mejor contraste
|
6 |
+
font = "sans serif"
|
7 |
# 335095
|
Readme.md
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gemini Chatbot Interface with Streamlit
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
|
5 |
+
This project is a Streamlit-based chat application that interacts with the Gemini AI model, allowing users to engage in conversations with an artificial intelligence assistant. The application stores chat history, allowing users to revisit and continue previous conversations.
|
6 |
+
|
7 |
+
<div align="center"><img src="docs/gemini-chatbot.gif" width="800"></div>
|
8 |
+
|
9 |
+
## Getting Started
|
10 |
+
|
11 |
+
### Dependencies
|
12 |
+
|
13 |
+
This code uses the following libraries:
|
14 |
+
|
15 |
+
- `streamlit`: for building the user interface.
|
16 |
+
- `gemini`: for chat
|
17 |
+
- Gemini API key: Get it from [Google AI Studio](https://ai.google.dev/tutorials/setup?hl=tr)
|
18 |
+
|
19 |
+
|
20 |
+
### Usage
|
21 |
+
|
22 |
+
Follow these steps to set up and run the project:
|
23 |
+
|
24 |
+
1. Create a virtual environment:
|
25 |
+
```
|
26 |
+
python3 -m venv my_env
|
27 |
+
source my_env/bin/activate
|
28 |
+
.\my_env\Scripts\activate
|
29 |
+
```
|
30 |
+
|
31 |
+
2. Install dependencies:
|
32 |
+
```
|
33 |
+
pip install -r requirements.txt
|
34 |
+
```
|
35 |
+
|
36 |
+
3. Run the Streamlit server:
|
37 |
+
```
|
38 |
+
streamlit run app_chat.py
|
39 |
+
```
|
40 |
+
|
41 |
+
4. Access the application in your browser at http://localhost:8501.
|
42 |
+
|
43 |
+
5. Start chatting with the assistant!
|
44 |
+
|
45 |
+
## Repository Structure
|
46 |
+
```
|
47 |
+
repository/
|
48 |
+
├── app_chat.py # the code and UI integrated together live here
|
49 |
+
├── requirements.txt # the python packages needed to run locally
|
50 |
+
├── .streamlit/
|
51 |
+
│ └── config.toml # theme info for the UI
|
52 |
+
├── data/ # folder for saved chat messages
|
53 |
+
├── docs/ # preview for github
|
54 |
+
|
55 |
+
```
|
56 |
+
|
57 |
+
## How it Works
|
58 |
+
|
59 |
+
The app as follows:
|
60 |
+
|
61 |
+
1. The user enters a question in the input field.
|
62 |
+
|
63 |
+
2. User messages are sent to the Gemini model for processing.
|
64 |
+
|
65 |
+
3. The user's input, along with the chat history, is used to generate a response.
|
66 |
+
|
67 |
+
4. The Gemini model generates a response based on the patterns it learned during training.
|
68 |
+
|
69 |
+
5. The application saves chat messages and Gemini AI chat history to files for later retrieval.
|
70 |
+
|
71 |
+
6. A new chat is created if the user initiates a conversation that hasn't been stored before, or user can go back to past chats.
|
app.py
CHANGED
@@ -10,7 +10,8 @@ genai.configure(api_key=GOOGLE_API_KEY)
|
|
10 |
|
11 |
new_chat_id = f'{time.time()}'
|
12 |
MODEL_ROLE = 'ai'
|
13 |
-
AI_AVATAR_ICON = '
|
|
|
14 |
|
15 |
# Create a data/ folder if it doesn't already exist
|
16 |
try:
|
@@ -27,6 +28,7 @@ except:
|
|
27 |
|
28 |
# Sidebar allows a list of past chats
|
29 |
with st.sidebar:
|
|
|
30 |
st.write('# Past Chats')
|
31 |
if st.session_state.get('chat_id') is None:
|
32 |
st.session_state.chat_id = st.selectbox(
|
@@ -77,13 +79,13 @@ for message in st.session_state.messages:
|
|
77 |
st.markdown(message['content'])
|
78 |
|
79 |
# React to user input
|
80 |
-
if prompt := st.chat_input('
|
81 |
# Save this as a chat for later
|
82 |
if st.session_state.chat_id not in past_chats.keys():
|
83 |
past_chats[st.session_state.chat_id] = st.session_state.chat_title
|
84 |
joblib.dump(past_chats, 'data/past_chats_list')
|
85 |
# Display user message in chat message container
|
86 |
-
with st.chat_message('user'):
|
87 |
st.markdown(prompt)
|
88 |
# Add user message to chat history
|
89 |
st.session_state.messages.append(
|
|
|
10 |
|
11 |
new_chat_id = f'{time.time()}'
|
12 |
MODEL_ROLE = 'ai'
|
13 |
+
AI_AVATAR_ICON = '🤖' # Cambia el emoji por uno de robot para coincidir con tu logo
|
14 |
+
USER_AVATAR_ICON = '👤' # Añade un avatar para el usuario
|
15 |
|
16 |
# Create a data/ folder if it doesn't already exist
|
17 |
try:
|
|
|
28 |
|
29 |
# Sidebar allows a list of past chats
|
30 |
with st.sidebar:
|
31 |
+
st.image("assets/robocopy_logo.png", width=200) # Añade tu logo
|
32 |
st.write('# Past Chats')
|
33 |
if st.session_state.get('chat_id') is None:
|
34 |
st.session_state.chat_id = st.selectbox(
|
|
|
79 |
st.markdown(message['content'])
|
80 |
|
81 |
# React to user input
|
82 |
+
if prompt := st.chat_input('¿En qué puedo ayudarte hoy?'): # Mensaje más amigable
|
83 |
# Save this as a chat for later
|
84 |
if st.session_state.chat_id not in past_chats.keys():
|
85 |
past_chats[st.session_state.chat_id] = st.session_state.chat_title
|
86 |
joblib.dump(past_chats, 'data/past_chats_list')
|
87 |
# Display user message in chat message container
|
88 |
+
with st.chat_message('user', avatar=USER_AVATAR_ICON): # Añade el avatar del usuario
|
89 |
st.markdown(prompt)
|
90 |
# Add user message to chat history
|
91 |
st.session_state.messages.append(
|
assets/robocopy_logo.png
ADDED
![]() |