Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,17 @@
|
|
1 |
-
import
|
2 |
-
from groq import Client, ModelType
|
3 |
|
4 |
-
|
5 |
-
GROQ_API_KEY = "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"
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
client = Client(api_key=GROQ_API_KEY)
|
10 |
-
model = client.model(ModelType.Claude_V1) # Change model type if desired
|
11 |
-
response = model.generate(prompt)
|
12 |
-
return response.text
|
13 |
-
|
14 |
-
# Streamlit app layout
|
15 |
-
st.title("Interactive Chatbot")
|
16 |
-
|
17 |
-
# Input field for user message
|
18 |
-
user_input = st.text_input("You: ", key="user_input")
|
19 |
-
|
20 |
-
# Display chat history (optional, can be implemented with a list)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
#
|
32 |
-
|
33 |
-
# Run the app
|
34 |
-
if __name__ == "__main__":
|
35 |
-
st.sidebar.title("Settings")
|
36 |
-
# Add any additional settings options here (e.g., model selection)
|
37 |
-
st.sidebar.write("Groq API Key: (hidden for security)")
|
38 |
-
st.sidebar.success("Connected to Groq!")
|
39 |
-
st.balloons() # Enable notification popups for user interaction
|
40 |
-
st.experimental_autogenerated_data_reports() # Enable data reports
|
41 |
-
st.server.main()
|
|
|
1 |
+
import os
|
|
|
2 |
|
3 |
+
from groq import Groq
|
|
|
4 |
|
5 |
+
# Initialize Groq client
|
6 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def get_response(prompt):
|
9 |
+
# Create chat completion request
|
10 |
+
chat_completion = client.chat.completions.create(
|
11 |
+
messages=[{"role": "user", "content": prompt}],
|
12 |
+
model="your_desired_model" # Replace with your preferred model
|
13 |
+
)
|
14 |
+
# Return the first choice's message content
|
15 |
+
return chat_completion.choices[0].message.content
|
16 |
+
|
17 |
+
# Rest of your Streamlit app code using get_response function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|