Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +32 -14
- assets/logo.png +0 -0
- requirements.txt +2 -9
app.py
CHANGED
|
@@ -1,21 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
st.
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Configuració de la pàgina
|
| 6 |
+
st.set_page_config(page_title='Portal Corporatiu IA', layout='wide')
|
| 7 |
|
| 8 |
+
# Logo i títol
|
| 9 |
+
st.image('assets/logo.png', width=150)
|
| 10 |
+
st.title('Portal Corporatiu amb IA')
|
| 11 |
|
| 12 |
+
# Sidebar premium
|
| 13 |
+
st.sidebar.title('Menú')
|
| 14 |
+
st.sidebar.markdown('''
|
| 15 |
+
- **FAQs**
|
| 16 |
+
- **Recursos**
|
| 17 |
+
- **Manteniment**
|
| 18 |
+
''')
|
| 19 |
|
| 20 |
+
# Clau API (variable d'entorn)
|
| 21 |
+
api_key = os.getenv('OPENAI_API_KEY')
|
| 22 |
+
if not api_key:
|
| 23 |
+
st.warning('⚠️ Defineix la variable OPENAI_API_KEY per usar GPT-3.5')
|
| 24 |
|
| 25 |
+
# Inicialitzar client OpenAI
|
| 26 |
+
client = OpenAI(api_key=api_key) if api_key else None
|
| 27 |
+
|
| 28 |
+
# Entrada usuari
|
| 29 |
+
prompt = st.text_area('Escriu la teva consulta:')
|
| 30 |
+
if st.button('Enviar') and prompt:
|
| 31 |
+
if client:
|
| 32 |
+
with st.spinner('Generant resposta...'):
|
| 33 |
+
response = client.chat.completions.create(
|
| 34 |
+
model='gpt-3.5-turbo',
|
| 35 |
+
messages=[{"role": "user", "content": prompt}]
|
| 36 |
+
)
|
| 37 |
+
st.success(response.choices[0].message.content)
|
| 38 |
+
else:
|
| 39 |
+
st.error('No hi ha clau API configurada.')
|
assets/logo.png
ADDED
|
requirements.txt
CHANGED
|
@@ -1,9 +1,2 @@
|
|
| 1 |
-
streamlit
|
| 2 |
-
|
| 3 |
-
sentence-transformers
|
| 4 |
-
faiss-cpu
|
| 5 |
-
python-dotenv
|
| 6 |
-
unstructured
|
| 7 |
-
pypdf
|
| 8 |
-
pillow
|
| 9 |
-
tiktoken
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
openai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|