| | import os |
| | from groq import Groq |
| | import streamlit as st |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| | api_key = os.getenv("GROQ_API_KEY") |
| |
|
| | |
| | client = Groq(api_key=api_key) |
| |
|
| | |
| | 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" |
| | ] |
| |
|
| | |
| | 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 transcribe_audio(file): |
| | transcription = client.audio.transcriptions.create( |
| | file=(file.name, file.read()), |
| | model="whisper-large-v3-turbo", |
| | response_format="verbose_json" |
| | ) |
| | return transcription.text |
| |
|
| | def main(): |
| | st.title("Programming Developer Advisor Chatbot") |
| |
|
| | |
| | topic = st.selectbox("Choose a programming topic", developer_topics) |
| | user_input = st.text_area("Or ask a programming-related question:", "") |
| |
|
| | |
| | uploaded_file = st.file_uploader("Upload an audio file for transcription", type=["m4a", "mp3", "wav"]) |
| |
|
| | |
| | if uploaded_file is not None: |
| | st.write("Transcribing the audio...") |
| | transcription = transcribe_audio(uploaded_file) |
| | st.write("Transcribed text:") |
| | st.write(transcription) |
| |
|
| | |
| | query = transcription if not user_input else user_input |
| |
|
| | |
| | if query: |
| | response = get_response(query) |
| | st.write("### Response:") |
| | st.write(response) |
| | |
| | |
| | elif user_input: |
| | query = user_input |
| | response = get_response(query) |
| | st.write("### Response:") |
| | st.write(response) |
| |
|
| | |
| | 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() |