meesamraza's picture
Update app.py
034d7bc verified
import os
from groq import Groq
import streamlit as st
from dotenv import load_dotenv
# Load API key from .env file
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")
# Initialize the Groq client
client = Groq(api_key=api_key)
# Define the business topics for the chatbot
business_topics = [
"marketing strategies", "business growth", "entrepreneurship", "sales techniques",
"investment strategies", "financial planning", "startup advice", "business management",
"leadership", "branding", "customer service", "business ethics", "negotiation",
"time management", "networking", "scaling a business", "business models",
"product development", "team building", "strategic planning", "e-commerce",
"online marketing", "fundraising", "small business", "business automation",
"social media marketing", "corporate social responsibility", "business partnerships"
]
# Function to fetch chatbot completion from Groq API
def get_response(query):
completion = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[{"role": "user", "content": query}],
temperature=0.7,
max_completion_tokens=1024,
top_p=1,
)
response = completion.choices[0].message.content
return response
def main():
st.title("Business Advice Chatbot")
# Let the user choose a business topic or type a custom query
topic = st.selectbox("Choose a business topic", business_topics)
user_input = st.text_area("Or ask a business-related question:", "")
# If the user provides a query, we use that
query = user_input if user_input else f"Tell me about {topic}"
# Create a submit button
submit_button = st.button("Submit")
# Call the Groq API to get the response if the button is clicked
if submit_button and query:
response = get_response(query)
# Display the response
st.write("### Response:")
st.write(response)
# Handle unrelated queries
if user_input and not any(topic in user_input.lower() for topic in business_topics):
st.write("Sorry, I can only answer business-related questions.")
if __name__ == "__main__":
main()