File size: 2,196 Bytes
81edbed
 
 
 
 
 
 
 
 
 
 
 
034d7bc
 
 
 
 
 
 
 
 
 
81edbed
 
 
 
 
 
 
 
 
 
 
 
 
 
034d7bc
81edbed
034d7bc
 
 
81edbed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
034d7bc
 
81edbed
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()