Abbas0786 commited on
Commit
75ae17a
·
verified ·
1 Parent(s): 0aeb743

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
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 your API key
11
- client = Groq(api_key="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")
 
 
 
 
 
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
- # Call Groq API to get the AI's response
25
- chat_completion = client.chat.completions.create(
26
- messages=st.session_state['messages'],
27
- model="llama3-8b-8192" # Specify model you want to use from Groq
28
- )
29
-
30
- ai_message = chat_completion.choices[0].message.content
31
- st.session_state['messages'].append({"role": "assistant", "content": ai_message})
32
-
33
- return ai_message
 
 
 
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')