Spaces:
Running
Running
Matias Stager
commited on
Commit
·
e7ef0c0
1
Parent(s):
81d2330
Inicio de Repositorio ChileanGPT
Browse files- .gitignore +4 -0
- README.md +3 -3
- app.py +42 -0
- requirements.txt +4 -0
- utils.py +22 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .gitignore
|
2 |
+
|
3 |
+
# Ignora el archivo .env
|
4 |
+
.env
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: ChileanGPT
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.19.0
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: ChileanGPT
|
3 |
+
emoji: 🤙
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.19.0
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_chat import message
|
3 |
+
from utils import get_initial_message, get_chatgpt_response, update_chat
|
4 |
+
import os
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
load_dotenv()
|
7 |
+
import openai
|
8 |
+
|
9 |
+
openai.api_key = os.getenv('openai_key')
|
10 |
+
|
11 |
+
st.title("Conversa con un Chileno")
|
12 |
+
|
13 |
+
if 'generated' not in st.session_state:
|
14 |
+
st.session_state['generated'] = []
|
15 |
+
if 'past' not in st.session_state:
|
16 |
+
st.session_state['past'] = []
|
17 |
+
|
18 |
+
query = st.text_input("Di algo:", key="input")
|
19 |
+
|
20 |
+
if 'messages' not in st.session_state:
|
21 |
+
st.session_state['messages'] = get_initial_message()
|
22 |
+
|
23 |
+
if query:
|
24 |
+
with st.spinner("pensando..."):
|
25 |
+
messages = st.session_state['messages']
|
26 |
+
messages = update_chat(messages, "user", query)
|
27 |
+
# st.write("Before making the API call")
|
28 |
+
# st.write(messages)
|
29 |
+
response = get_chatgpt_response(messages,"gpt-3.5-turbo")
|
30 |
+
messages = update_chat(messages, "assistant", response)
|
31 |
+
st.session_state.generated.append(response)
|
32 |
+
st.session_state.past.append(query)
|
33 |
+
|
34 |
+
|
35 |
+
if st.session_state['generated']:
|
36 |
+
|
37 |
+
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
38 |
+
message(st.session_state["generated"][i], key=str(i))
|
39 |
+
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
40 |
+
|
41 |
+
# # with st.expander("Mensajes"):
|
42 |
+
# st.write(messages)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
streamlit_chat
|
3 |
+
openai
|
4 |
+
python-dotenv
|
utils.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
|
3 |
+
def get_initial_message():
|
4 |
+
messages=[
|
5 |
+
{"role": "system", "content": "Actua como un Flaite Chileno, llamado Kevin, que es originario de San Bernardo, Santiago de Chile, te gusta escuchar musica urbana, en especial a Marcianeke y Pailita. Hablas como un flaite chileno bien tipico y exagerado, eres chistoso, informal y a veces un poco grosero. Responde lo necesario sin dar explicaicones extensas."},
|
6 |
+
{"role": "user", "content": "Hola, cómo estás?"},
|
7 |
+
{"role": "assistant", "content": "Wena hermanito, puro tirando pa' arriba no más, y vo?"}
|
8 |
+
]
|
9 |
+
return messages
|
10 |
+
|
11 |
+
def get_chatgpt_response(messages, model="gpt-3.5-turbo"):
|
12 |
+
print("Pregunta: ", messages)
|
13 |
+
response = openai.ChatCompletion.create(
|
14 |
+
model=model,
|
15 |
+
messages=messages
|
16 |
+
)
|
17 |
+
print ("respuesta",response)
|
18 |
+
return response['choices'][0]['message']['content']
|
19 |
+
|
20 |
+
def update_chat(messages, role, content):
|
21 |
+
messages.append({"role": role, "content": content})
|
22 |
+
return messages
|