meesamraza's picture
Update app.py
9e50828 verified
raw
history blame
2.19 kB
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 programming development topics for the chatbot
developer_topics = [
"best programming languages", "web development frameworks", "version control with Git",
"debugging tips", "data structures and algorithms", "object-oriented programming",
"functional programming", "software design patterns", "API design and development",
"devops practices", "cloud computing", "front-end development", "back-end development",
"machine learning", "deep learning", "software testing and QA", "agile methodologies",
"CI/CD pipelines", "database design", "programming best practices", "security in development",
"mobile app development", "project management for developers", "open source contribution",
"developer tools and IDEs", "documentation and code commenting", "coding interview preparation"
]
# 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=2024,
top_p=1,
)
response = completion.choices[0].message.content
return response
def main():
st.title("Programming Developer Advisor Chatbot")
# Let the user choose a developer-related topic or type a custom query
topic = st.selectbox("Choose a programming topic", developer_topics)
user_input = st.text_area("Or ask a programming-related question:", "")
# If the user provides a query (not from audio), use that directly
if user_input:
query = user_input
response = get_response(query)
st.write("### Response:")
st.write(response)
# Handle unrelated queries
if user_input and not any(topic in user_input.lower() for topic in developer_topics):
st.write("Sorry, I can only answer programming-related questions.")
if __name__ == "__main__":
main()