Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|