Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,13 @@ import pandas as pd
|
|
| 7 |
from streamlit.components.v1 import html
|
| 8 |
from groq import Groq
|
| 9 |
|
| 10 |
-
# Initialize Groq client with
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Set up the title and description for the Streamlit app
|
| 14 |
st.set_page_config(page_title="Gaia: Women Safety App", page_icon="🤖", layout="centered")
|
|
@@ -21,16 +26,19 @@ def get_response(user_input):
|
|
| 21 |
|
| 22 |
st.session_state['messages'].append({"role": "user", "content": user_input})
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Sidebar for navigation
|
| 36 |
st.sidebar.title('Features')
|
|
|
|
| 7 |
from streamlit.components.v1 import html
|
| 8 |
from groq import Groq
|
| 9 |
|
| 10 |
+
# Initialize Groq client with error handling
|
| 11 |
+
try:
|
| 12 |
+
client = Groq(api_key="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")
|
| 13 |
+
st.write("Groq client initialized successfully.")
|
| 14 |
+
except Exception as e:
|
| 15 |
+
st.error(f"Failed to initialize Groq client: {e}")
|
| 16 |
+
client = None # If the client fails to initialize, set it to None
|
| 17 |
|
| 18 |
# Set up the title and description for the Streamlit app
|
| 19 |
st.set_page_config(page_title="Gaia: Women Safety App", page_icon="🤖", layout="centered")
|
|
|
|
| 26 |
|
| 27 |
st.session_state['messages'].append({"role": "user", "content": user_input})
|
| 28 |
|
| 29 |
+
if client:
|
| 30 |
+
# Call Groq API to get the AI's response
|
| 31 |
+
chat_completion = client.chat.completions.create(
|
| 32 |
+
messages=st.session_state['messages'],
|
| 33 |
+
model="llama3-8b-8192" # Specify model you want to use from Groq
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
ai_message = chat_completion.choices[0].message.content
|
| 37 |
+
st.session_state['messages'].append({"role": "assistant", "content": ai_message})
|
| 38 |
+
|
| 39 |
+
return ai_message
|
| 40 |
+
else:
|
| 41 |
+
return "Error: Groq client not initialized."
|
| 42 |
|
| 43 |
# Sidebar for navigation
|
| 44 |
st.sidebar.title('Features')
|