engrharis commited on
Commit
9bfae5f
·
verified ·
1 Parent(s): 618f204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -38
app.py CHANGED
@@ -1,41 +1,17 @@
1
- import streamlit as st
2
- from groq import Client, ModelType
3
 
4
- # Replace with your Groq API key
5
- GROQ_API_KEY = "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"
6
 
7
- # Define a function to get chatbot response
8
- def get_response(prompt):
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
- # Generate response if user enters something
23
- if user_input:
24
- # Get response from Groq API
25
- bot_response = get_response(user_input)
26
- st.write("Bot: ", bot_response)
27
-
28
- # Deployment on Hugging Face (refer to their documentation)
29
- # This code snippet is not included as it involves specific steps on their platform.
30
- # You can find deployment instructions for Streamlit apps on Hugging Face Spaces here:
31
- # https://docs.huggingface.com/notebooks/streamlit/
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